Skip to content

Commit

Permalink
GitHub svg media library preview support (#954)
Browse files Browse the repository at this point in the history
* Append sanitize query to svg download_url

* Add svg ext to media viewable

* Append searchParam manually
  • Loading branch information
Jinksi authored and tech4him1 committed Jan 4, 2018
1 parent b927c8a commit b8c411c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/backends/github/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ export default class GitHub {
return this.api.listFiles(this.config.get('media_folder'))
.then(files => files.filter(file => file.type === 'file'))
.then(files => files.map(({ sha, name, size, download_url, path }) => {
return { id: sha, name, size, url: download_url, path };
const url = new URL(download_url);
if (url.pathname.match(/.svg$/)) {
url.search += (url.search.slice(1) === '' ? '?' : '&') + 'sanitize=true';
}
return { id: sha, name, size, url: url.href, path };
}));
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/MediaLibrary/MediaLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { Icon } from 'UI';
* Extensions used to determine which files to show when the media library is
* accessed from an image insertion field.
*/
const IMAGE_EXTENSIONS_VIEWABLE = [ 'jpg', 'jpeg', 'webp', 'gif', 'png', 'bmp', 'tiff' ];
const IMAGE_EXTENSIONS = [ ...IMAGE_EXTENSIONS_VIEWABLE, 'svg' ];
const IMAGE_EXTENSIONS_VIEWABLE = [ 'jpg', 'jpeg', 'webp', 'gif', 'png', 'bmp', 'tiff', 'svg' ];
const IMAGE_EXTENSIONS = [ ...IMAGE_EXTENSIONS_VIEWABLE ];

class MediaLibrary extends React.Component {

Expand Down

0 comments on commit b8c411c

Please sign in to comment.