Skip to content

Commit

Permalink
Add ability to look up page mime types from media.yaml - #966
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Aug 10, 2016
1 parent 1c462e8 commit b3f35fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ public function redirectLangSafe($route, $code = null)
*/
public function mime($format)
{
// look for some standard types
switch ($format) {
case null:
return 'text/html';
case 'json':
return 'application/json';
case 'html':
Expand All @@ -230,6 +233,16 @@ public function mime($format)
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';
}

Expand Down

0 comments on commit b3f35fb

Please sign in to comment.