diff --git a/CHANGELOG.md b/CHANGELOG.md index 0597fdac1..f7565f762 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ 1. [](#improved) * Improved `authorize` Twig extension to accept a nested array of authorizations [#948](https://github.com/getgrav/grav/issues/948) * Don't add timestamps on remote assets as it can cause conflicts + * Grav now looks at types from `media.yaml` when retrieving page mime types [#966](https://github.com/getgrav/grav/issues/966) 1. [](#bugfix) * Fixed `Folder::delete` method to recursively remove files and folders and causing Upgrade to fail. * Fix [#952](https://github.com/getgrav/grav/issues/952) hypenize the session name. diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 0ec82f8d0..05041f9bd 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -217,7 +217,10 @@ class Grav extends Container */ public function mime($format) { + // look for some standard types switch ($format) { + case null: + return 'text/html'; case 'json': return 'application/json'; case 'html': @@ -230,6 +233,16 @@ class Grav extends Container return 'application/xml'; } + // Try finding mime type from media + $media_types = $this['config']->get('media.types'); + if (key_exists($format, $media_types)) { + $type = $media_types[$format]; + if (isset($type['mime'])) { + return $type['mime']; + } + } + + // Can't find the mime type, send as HTML return 'text/html'; }