diff --git a/sitegin/image.js b/sitegin/image.js index a31e896942cd148e293f0440639bc9f21a8c5a23..25b9ac3ca201cae6cc562d0eeacf3db647caac6d 100644 --- a/sitegin/image.js +++ b/sitegin/image.js @@ -7,32 +7,21 @@ const { rewriteURL } = require('./urls') const generateImage = (file, targetDir, width, height) => jobs.run('imageResizer', file, targetDir, width, height) -const paramInHrefParser = href => { - const sepIndex = href.indexOf(' =') - const ret = { +function fromEntries(entries) { + return [...entries].reduce((o, [k,v]) => { + o[k] = v + return o + }, {}) +} + +const paramInHrefParser = href_ => { + const [href, ...searchArr] = href_.split('?') + const search = searchArr.join('?') + const params = new URLSearchParams(search) + return { href, - options: {}, + options: fromEntries(params.entries()), } - if (sepIndex < 0) { - return ret - } - ret.href = href.substr(0, sepIndex) - let options = href.substr(sepIndex + 2) - options = options // split by ',' but not '\,' - .replace('a,', '\u0007') - .split(',') - .map(e => e.replace('\u0007', 'a,')) - options.forEach(option => { - const index = option.indexOf('=') - if (index < 0) { - ret.options[option] = true - } else { - const key = option.substr(0, index) - const value = option.substr(index + 1) - ret.options[key] = value - } - }) - return ret } const renderYoutube = href => {