Sorry, I'm still having a hard time understanding, trying to get this to work inside my NJK file.
Receiving ,Error: Input file is missing .
I'm using the Eleventy Base Blog.
Please help!
.eleventyconfig
const Image = require("@11ty/eleventy-img");
module.exports = function(eleventyConfig) {
eleventyConfig.addNunjucksAsyncShortcode("myImage", async function(src, alt, outputFormat = "jpeg") {
let stats = await Image(src, {
formats: [outputFormat],
widths: [360, null],
urlPath: "/img/",
outputDir: "img/",
});
let props = stats[outputFormat].pop();
if (alt === undefined) {
throw new Error(`Missing \`alt\` on myImage from: ${src}`);
}
return `<img src="${props.src}" width="${props.width}" height="${props.height}" alt="${alt}">`;
});
};
Nunjucks template:
{% myImage "someimage.jpg", "Some alt text" %}
Sorry, I'm still having a hard time understanding, trying to get this to work inside my NJK file.
Receiving ,
Error: Input file is missing.I'm using the Eleventy Base Blog.
Please help!
.eleventyconfigNunjucks template: