Added shortcode for Umami analytics
This commit is contained in:
parent
aae0aa4104
commit
9a724a2c43
2 changed files with 22 additions and 1 deletions
|
|
@ -92,7 +92,27 @@ export default async function (eleventyConfig) {
|
||||||
eleventyConfig.addShortcode('imageKeys', shortcodes.imageKeysShortcode);
|
eleventyConfig.addShortcode('imageKeys', shortcodes.imageKeysShortcode);
|
||||||
eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`);
|
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 `<script defer src="https://umami.hypnagaga.com/script.js" data-website-id="5b310c0d-84a4-4435-a4f4-a3c093a1b07a"></script>`;
|
||||||
|
}
|
||||||
|
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 <img> tag
|
||||||
|
return imageHtml.replace('<img', '<img data-pagefind-meta="image[src]"');
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
|
// --------------------- Events ---------------------
|
||||||
if (process.env.ELEVENTY_RUN_MODE === 'serve') {
|
if (process.env.ELEVENTY_RUN_MODE === 'serve') {
|
||||||
eleventyConfig.on('eleventy.after', events.svgToJpeg);
|
eleventyConfig.on('eleventy.after', events.svgToJpeg);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,5 @@
|
||||||
<custom-easteregg></custom-easteregg>
|
<custom-easteregg></custom-easteregg>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</body>
|
</body>
|
||||||
|
{% umami %}
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue