markdown global rendering engine and link customization
This commit is contained in:
parent
b0994e0465
commit
b09d4a8591
|
@ -4,7 +4,6 @@ title: Programm
|
||||||
tags: mainNav
|
tags: mainNav
|
||||||
eleventyNavigation:
|
eleventyNavigation:
|
||||||
order: 1
|
order: 1
|
||||||
templateEngineOverride: njk,md
|
|
||||||
---
|
---
|
||||||
# Programm
|
# Programm
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ title: Program
|
||||||
tags: mainNav
|
tags: mainNav
|
||||||
eleventyNavigation:
|
eleventyNavigation:
|
||||||
order: 1
|
order: 1
|
||||||
templateEngineOverride: njk,md
|
|
||||||
---
|
---
|
||||||
# Program
|
# Program
|
||||||
|
|
||||||
|
|
|
@ -92,28 +92,32 @@ module.exports = function(eleventyConfig) {
|
||||||
return value.filter(item => item.page.lang === this.page.lang)
|
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) {
|
eleventyConfig.addAsyncFilter('mdInline', async function(value) {
|
||||||
// TODO replace with ESM import once we switch to Eleventy v3
|
// TODO replace with ESM import once we switch to Eleventy v3
|
||||||
const md = (await import('markdown-it/index.mjs')).default();
|
const md = (await import('markdown-it/index.mjs')).default();
|
||||||
|
|
||||||
// customize link rendering
|
// customize link rendering
|
||||||
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
md.renderer.rules.link_open = md_link_open;
|
||||||
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
return md.renderInline(value);
|
return md.renderInline(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eleventyConfig.amendLibrary("md", mdLib => mdLib.renderer.rules.link_open = md_link_open);
|
||||||
|
|
||||||
// copy aileron font
|
// copy aileron font
|
||||||
eleventyConfig.addPassthroughCopy({'./submodules/aileron/fonts/*.(ttf|woff|woff2)': 'fonts'})
|
eleventyConfig.addPassthroughCopy({'./submodules/aileron/fonts/*.(ttf|woff|woff2)': 'fonts'})
|
||||||
eleventyConfig.addPassthroughCopy({'./submodules/aileron/aileron.lite.min.css': 'aileron.lite.min.css'})
|
eleventyConfig.addPassthroughCopy({'./submodules/aileron/aileron.lite.min.css': 'aileron.lite.min.css'})
|
||||||
|
@ -140,5 +144,6 @@ module.exports = function(eleventyConfig) {
|
||||||
includes: "../_includes",
|
includes: "../_includes",
|
||||||
},
|
},
|
||||||
pathPrefix: `/${eseData.year}/`,
|
pathPrefix: `/${eseData.year}/`,
|
||||||
|
markdownTemplateEngine: "njk",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue