From b09d4a859122e3203c781f0e2b1a83a147ea3ef4 Mon Sep 17 00:00:00 2001 From: Lyn Fugmann Date: Wed, 2 Oct 2024 15:19:22 +0200 Subject: [PATCH] markdown global rendering engine and link customization --- content/de/program.md | 1 - content/en/program.md | 1 - eleventy.config.js | 31 ++++++++++++++++++------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/content/de/program.md b/content/de/program.md index bb988e2..1b69436 100644 --- a/content/de/program.md +++ b/content/de/program.md @@ -4,7 +4,6 @@ title: Programm tags: mainNav eleventyNavigation: order: 1 -templateEngineOverride: njk,md --- # Programm diff --git a/content/en/program.md b/content/en/program.md index 46b04ae..7b1c034 100644 --- a/content/en/program.md +++ b/content/en/program.md @@ -4,7 +4,6 @@ title: Program tags: mainNav eleventyNavigation: order: 1 -templateEngineOverride: njk,md --- # Program diff --git a/eleventy.config.js b/eleventy.config.js index a519c71..76e8f0e 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -92,28 +92,32 @@ module.exports = function(eleventyConfig) { return value.filter(item => item.page.lang === this.page.lang) }); + const md_link_open = function (tokens, idx, options, env, self) { + const href = tokens[idx].attrGet('href'); + + if (href.startsWith('http')) { + tokens[idx].attrSet('target', '_blank'); + tokens[idx].attrSet('rel', 'noreferrer'); + } else { + const newHref = eleventyConfig.javascriptFunctions.locale_url(href); + tokens[idx].attrSet('href', newHref); + } + + return self.renderToken(tokens, idx, options); + }; + eleventyConfig.addAsyncFilter('mdInline', async function(value) { // TODO replace with ESM import once we switch to Eleventy v3 const md = (await import('markdown-it/index.mjs')).default(); // customize link rendering - md.renderer.rules.link_open = function (tokens, idx, options, env, self) { - const href = tokens[idx].attrGet('href'); - - if (href.startsWith('http')) { - tokens[idx].attrSet('target', '_blank'); - tokens[idx].attrSet('rel', 'noreferrer'); - } else { - const newHref = eleventyConfig.javascriptFunctions.locale_url(href); - tokens[idx].attrSet('href', newHref); - } - - return self.renderToken(tokens, idx, options); - }; + md.renderer.rules.link_open = md_link_open; return md.renderInline(value); }); + eleventyConfig.amendLibrary("md", mdLib => mdLib.renderer.rules.link_open = md_link_open); + // copy aileron font eleventyConfig.addPassthroughCopy({'./submodules/aileron/fonts/*.(ttf|woff|woff2)': 'fonts'}) eleventyConfig.addPassthroughCopy({'./submodules/aileron/aileron.lite.min.css': 'aileron.lite.min.css'}) @@ -140,5 +144,6 @@ module.exports = function(eleventyConfig) { includes: "../_includes", }, pathPrefix: `/${eseData.year}/`, + markdownTemplateEngine: "njk", } };