From b050a975cf6a71543baef5058d0cc5de70db0e8b Mon Sep 17 00:00:00 2001 From: John Kavanagh Date: Thu, 29 Oct 2020 13:08:51 +0000 Subject: [PATCH 1/2] fix for es5 compatibility --- components/x-teaser/src/Image.jsx | 2 +- components/x-teaser/src/concerns/image-service.js | 11 ++++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/x-teaser/src/Image.jsx b/components/x-teaser/src/Image.jsx index 3c02bacc8..3a430a0aa 100644 --- a/components/x-teaser/src/Image.jsx +++ b/components/x-teaser/src/Image.jsx @@ -46,4 +46,4 @@ export default ({ relativeUrl, url, image, imageSize, imageLazyLoad, imageHighes ) : null; -}; +}; \ No newline at end of file diff --git a/components/x-teaser/src/concerns/image-service.js b/components/x-teaser/src/concerns/image-service.js index cf42141d3..a9cd96d6c 100644 --- a/components/x-teaser/src/concerns/image-service.js +++ b/components/x-teaser/src/concerns/image-service.js @@ -1,4 +1,3 @@ -const { URL, URLSearchParams } = require('url'); const BASE_URL = 'https://www.ft.com/__origami/service/image/v2/images/raw'; const OPTIONS = { source:'next', fit:'scale-down', dpr:2 }; @@ -9,8 +8,10 @@ const OPTIONS = { source:'next', fit:'scale-down', dpr:2 }; * @param {String} options */ export default function imageService(url, width, options) { - const imageSrc = new URL(`${BASE_URL}/${encodeURIComponent(url)}`); - imageSrc.search = new URLSearchParams({...OPTIONS, ...options }); - imageSrc.searchParams.set('width', width); - return imageSrc.href; + + const imageOptions = {...OPTIONS, ...options, width }; + const encoded = encodeURIComponent(url); + const optionsEncoded = Object.entries(imageOptions).map(([key,value])=>`&${key}=${value}`).join(''); + const href = `${BASE_URL}/${encoded}?${optionsEncoded}`; + return href; } diff --git a/package.json b/package.json index 60e22cc16..a0502a24e 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "eslint-plugin-react": "^7.13.0", "fetch-mock": "^7.3.3", "jest": "^24.8.0", - "node-sass": "^4.12.0", + "node-sass": "^4.14.1", "react": "^16.8.6", "react-helmet": "^5.2.0", "react-test-renderer": "^16.8.6", From ac0f7fd5c4042e24da9d91a202ed525d1a04b358 Mon Sep 17 00:00:00 2001 From: John Kavanagh Date: Thu, 29 Oct 2020 14:27:11 +0000 Subject: [PATCH 2/2] fix ampersand on first qs var --- components/x-teaser/src/concerns/image-service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/x-teaser/src/concerns/image-service.js b/components/x-teaser/src/concerns/image-service.js index a9cd96d6c..18f46d5a4 100644 --- a/components/x-teaser/src/concerns/image-service.js +++ b/components/x-teaser/src/concerns/image-service.js @@ -11,7 +11,7 @@ export default function imageService(url, width, options) { const imageOptions = {...OPTIONS, ...options, width }; const encoded = encodeURIComponent(url); - const optionsEncoded = Object.entries(imageOptions).map(([key,value])=>`&${key}=${value}`).join(''); + const optionsEncoded = Object.entries(imageOptions).map(([key,value],i)=>`${(i?'&':'')}${key}=${value}`).join(''); const href = `${BASE_URL}/${encoded}?${optionsEncoded}`; return href; }