diff --git a/eleventy.config.js b/eleventy.config.js index d1204fc..91bc1a0 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -92,7 +92,27 @@ export default async function (eleventyConfig) { eleventyConfig.addShortcode('imageKeys', shortcodes.imageKeysShortcode); eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`); - // --------------------- Events: after build + + eleventyConfig.addShortcode("umami", function () { + // Only insert tracking on production builds + if (process.env.ELEVENTY_ENV === "production" || process.env.NODE_ENV === "production") { + return ``; + } + return ""; // No script in dev builds + }); + + // Custom shortcode for the post feature image to add pagefind attribute + eleventyConfig.addAsyncShortcode('featureImage', async (src, alt, credit) => { + // call the original image shortcode with arguments for a feature image + const imageHtml = await shortcodes.imageShortcode(src, alt, credit, 'eager', 'feature'); + if (imageHtml) { + // inject the pagefind attribute into the tag + return imageHtml.replace(' {%- endif -%} + {% umami %}