From 9a724a2c430c5baf5d8e11e13d217c6ee4478b81 Mon Sep 17 00:00:00 2001 From: Ben Aultowski Date: Mon, 27 Oct 2025 16:57:16 -0400 Subject: [PATCH] Added shortcode for Umami analytics --- eleventy.config.js | 22 +++++++++++++++++++++- src/_layouts/base.njk | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) 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 %}