From cfe818d4b5e0f8600560040c9dd5c923f32ed31f Mon Sep 17 00:00:00 2001 From: Takuya Fukuju Date: Tue, 28 Mar 2023 20:17:19 +0900 Subject: [PATCH] =?UTF-8?q?refactor(eleventy):=20`set-image-dimensions`=20?= =?UTF-8?q?=E3=83=88=E3=83=A9=E3=83=B3=E3=82=B9=E3=83=95=E3=82=A9=E3=83=BC?= =?UTF-8?q?=E3=83=A0=E3=81=AE=E5=86=85=E9=83=A8=E9=96=A2=E6=95=B0=E3=82=92?= =?UTF-8?q?=E4=B8=A6=E3=81=B9=E6=9B=BF=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 11ty/transforms/set-image-dimensions.cjs | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/11ty/transforms/set-image-dimensions.cjs b/11ty/transforms/set-image-dimensions.cjs index fdfc46e7..2bde3859 100644 --- a/11ty/transforms/set-image-dimensions.cjs +++ b/11ty/transforms/set-image-dimensions.cjs @@ -27,24 +27,6 @@ const isUrl = (string) => { } }; -const rebaseSourceUrl = (sourceUrl, outputPath) => { - if (isUrl(sourceUrl)) { - return sourceUrl; - } - - if (isAbsolute(sourceUrl)) { - return join(config.get('srcDir'), sourceUrl); - } - - return join( - config.get('srcDir'), - relative( - join(config.get('distDir'), config.get('publicPath')), - join(dirname(outputPath), sourceUrl), - ), - ); -}; - const getMetadata = async (sourceUrl) => { if (isUrl(sourceUrl)) { const response = await fetch(sourceUrl); @@ -63,6 +45,24 @@ const getMetadata = async (sourceUrl) => { return sharp(sourceUrl).metadata(); }; +const rebaseSourceUrl = (sourceUrl, outputPath) => { + if (isUrl(sourceUrl)) { + return sourceUrl; + } + + if (isAbsolute(sourceUrl)) { + return join(config.get('srcDir'), sourceUrl); + } + + return join( + config.get('srcDir'), + relative( + join(config.get('distDir'), config.get('publicPath')), + join(dirname(outputPath), sourceUrl), + ), + ); +}; + const setDimensions = (element, width, height) => { if (!element.hasAttribute('width')) { element.setAttribute('width', width);