Skip to content

Commit

Permalink
refactor(eleventy): set-image-dimensions トランスフォームの内部関数を並べ替える
Browse files Browse the repository at this point in the history
  • Loading branch information
chalkygames123 committed Mar 28, 2023
1 parent 32b824b commit 0ebd8b1
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions 11ty/transforms/set-image-dimensions.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 0ebd8b1

Please sign in to comment.