Refactored image shortcode
This commit is contained in:
parent
dcbbc662d6
commit
94f0c3e5e7
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue