const Image = require('@11ty/eleventy-img'); const path = require('path'); const htmlmin = require('html-minifier'); const imageShortcodePlaceholder = async (src, alt, caption, sizes = '100vw') => { if (!alt) { throw new Error(`Missing \`alt\` on myImage from: ${src}`); } let metadata = await Image(src, { widths: [400, 700, 1280], formats: ['avif', 'webp', 'jpeg'], urlPath: '/assets/images/', outputDir: './dist/assets/images/', filenameFormat: function (id, src, width, format, options) { const extension = path.extname(src); const name = path.basename(src, extension); return `${name}-${width}w.${format}`; } }); let lowsrc = metadata.jpeg[0]; // getting the url to use let imgSrc = src; if (!imgSrc.startsWith('.')) { const inputPath = this.page.inputPath; const pathParts = inputPath.split('/'); pathParts.pop(); imgSrc = pathParts.join('/') + '/' + src; } return htmlmin.minify( `
${Object.values(metadata) .map(imageFormat => { return ` `; }) .join('\n')} ${alt} ${ caption ? `

${caption}

` : `` }
`, {collapseWhitespace: true} ); }; module.exports = imageShortcodePlaceholder;