Refactored image shortcode

This commit is contained in:
Claudia Reynders 2022-04-30 18:02:31 +02:00
parent dcbbc662d6
commit 94f0c3e5e7
1 changed files with 4 additions and 8 deletions

View File

@ -1,5 +1,4 @@
const Image = require("@11ty/eleventy-img") const Image = require('@11ty/eleventy-img')
const path = require('path')
const imageShortcode = async ( const imageShortcode = async (
relativeSrc, relativeSrc,
@ -9,14 +8,11 @@ const imageShortcode = async (
formats = ['webp'], formats = ['webp'],
sizes = '(min-width: 100px)' sizes = '(min-width: 100px)'
) => { ) => {
const { dir: imgDir } = path.parse(relativeSrc);
const fullSrc = path.join('src', relativeSrc);
const imageMetadata = await Image(relativeSrc, { const imageMetadata = await Image(relativeSrc, {
widths, widths,
formats, formats,
outputDir: "./_site/assets/images/generated/", outputDir: './_site/assets/images/generated/',
urlPath: "/assets/images/generated/", urlPath: '/assets/images/generated/',
}) })
const imageAttributes = { const imageAttributes = {
@ -26,7 +22,7 @@ const imageShortcode = async (
decoding: 'async', decoding: 'async',
} }
if(className) {imageAttributes["class"] = className } if(className) {imageAttributes['class'] = className }
return Image.generateHTML(imageMetadata, imageAttributes) return Image.generateHTML(imageMetadata, imageAttributes)
} }