Add enableLazyLoading parameter to figure element paired shortcode

This commit is contained in:
Helen Chong 2024-06-06 22:25:00 +08:00
parent a5b0567c8a
commit 832e1d07fd
1 changed files with 2 additions and 2 deletions

View File

@ -104,10 +104,10 @@ module.exports = function (eleventyConfig) {
}); });
// Paired shortcode: image figure and figcaption // Paired shortcode: image figure and figcaption
eleventyConfig.addPairedShortcode('imgFigure', (caption, img, alt=caption) => { eleventyConfig.addPairedShortcode('imgFigure', (caption, img, alt=caption, enableLazyLoading=true) => {
const figcaption = markdownLibrary.renderInline(caption); const figcaption = markdownLibrary.renderInline(caption);
return `<figure> return `<figure>
<img src="${img}" alt="${alt}"> <img src="${img}" alt="${alt}"${enableLazyLoading ? ' loading="lazy"' : ''}>
<figcaption>${figcaption}</figcaption> <figcaption>${figcaption}</figcaption>
</figure>`; </figure>`;
}); });