From aed1bdef7230e334edc8f0cdbdc0d5d9025261bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isabella=20Sko=C5=99epov=C3=A1?= <isabella@skorepova.info> Date: Thu, 7 Nov 2019 12:58:21 +0100 Subject: [PATCH] Fix image param parser --- sitegin/image.js | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/sitegin/image.js b/sitegin/image.js index a31e8969..25b9ac3c 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 => { -- GitLab