diff --git a/build/asset.js b/build/asset.js index 581a1cf..2a5d37c 100644 --- a/build/asset.js +++ b/build/asset.js @@ -1,6 +1,6 @@ const path = require('path'); -const { pick, each } = require('lodash'); +const { pick } = require('lodash'); const actions = require('./actions'); const File = require('./file'); const { TYPE } = require('./resolve'); @@ -56,7 +56,7 @@ module.exports = exports = class Asset extends File { height, } ]; - if (this.preprocessed) { + if (this.preprocessed || this.ext === '.svg') { this._tasks = [ { output: this.out, input: this.input, diff --git a/build/lib/dimensions.js b/build/lib/dimensions.js index 61c2413..2e243f8 100644 --- a/build/lib/dimensions.js +++ b/build/lib/dimensions.js @@ -1,3 +1,10 @@ var { promisify } = require('util'); -module.exports = exports = promisify(require('image-size')); +var { extname } = require('path'); +var svgDim = promisify(require('svg-dimensions').get); +var imgDim = promisify(require('image-size')); + +module.exports = exports = async (fpath) => { + if (extname(fpath) === '.svg') return svgDim(fpath); + return imgDim(fpath); +}; diff --git a/build/resolve.js b/build/resolve.js index 34cfb18..55c7b86 100644 --- a/build/resolve.js +++ b/build/resolve.js @@ -28,6 +28,7 @@ const EXT = exports.EXT = { JPEG: '.jpeg', PNG: '.png', GIF: '.gif', + SVG: '.svg', MP4: '.mp4', M4V: '.m4v', MD: '.md', @@ -45,6 +46,7 @@ const { JPEG, PNG, GIF, + SVG, MP4, M4V, MD, @@ -70,7 +72,7 @@ const normalizedExt = exports.normalizedExt = (ext) => { }; const isVideo = exports.isVideo = is(MP4, M4V); -const isImage = exports.isImage = is(JPG, JPEG, PNG, GIF); +const isImage = exports.isImage = is(JPG, JPEG, PNG, GIF, SVG); const isHandybars = exports.isHandybars = is(XML, HBS, HTML); const isMarkdown = exports.isMarkdown = is(MD); const isPage = exports.isPage = is(isHandybars, isMarkdown); diff --git a/package-lock.json b/package-lock.json index 8782aac..e75d29d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12288,6 +12288,15 @@ "es6-symbol": "^3.1.1" } }, + "svg-dimensions": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/svg-dimensions/-/svg-dimensions-1.0.2.tgz", + "integrity": "sha1-s1oDW91X/tJxaJMbmz1bC7VebtI=", + "dev": true, + "requires": { + "xml2js": "^0.4.5" + } + }, "svgo": { "version": "0.7.2", "resolved": "https://registry.npmjs.org/svgo/-/svgo-0.7.2.tgz", diff --git a/package.json b/package.json index 68bdd8e..82a6e7f 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "serve-index": "~1.9.1", "slugify": "~1.4.7", "string-strip-html": "~8.2.3", + "svg-dimensions": "~1.0.2", "terser": "~5.6.0", "twemoji": "~13.0.1", "twitter-lite": "~1.1.0",