2024-05-07 03:30:52 +00:00
|
|
|
|
/* CONFIGURATION FOR MARKDOWN TEMPLATES */
|
2024-05-06 17:37:15 +00:00
|
|
|
|
|
2024-05-06 17:01:15 +00:00
|
|
|
|
// Installed Plugins
|
2024-07-18 18:08:10 +00:00
|
|
|
|
import pluginTOC from '@uncenter/eleventy-plugin-toc';
|
|
|
|
|
import embedEverything from "eleventy-plugin-embed-everything";
|
2024-05-06 17:01:15 +00:00
|
|
|
|
|
|
|
|
|
// Configure slug filter
|
2024-07-18 18:08:10 +00:00
|
|
|
|
import slugify from "slugify";
|
2024-05-06 17:01:15 +00:00
|
|
|
|
|
2024-07-18 18:08:10 +00:00
|
|
|
|
// markdown-it plugins
|
|
|
|
|
import markdownIt from "markdown-it";
|
|
|
|
|
import markdownItAnchor from "markdown-it-anchor";
|
|
|
|
|
import markdownItAttribution from "markdown-it-attribution";
|
|
|
|
|
import markdownItAttrs from "markdown-it-attrs";
|
|
|
|
|
import markdownItBracketedSpans from 'markdown-it-bracketed-spans';
|
|
|
|
|
import markdownItDefList from "markdown-it-deflist";
|
|
|
|
|
import markdownItFootnote from "markdown-it-footnote";
|
|
|
|
|
|
|
|
|
|
export default function (eleventyConfig) {
|
2024-05-06 17:01:15 +00:00
|
|
|
|
// Installed Plugins
|
2024-07-14 02:52:19 +00:00
|
|
|
|
eleventyConfig.addPlugin(pluginTOC, {
|
|
|
|
|
tags: ['h2', 'h3', 'h4', 'h5', 'h6'],
|
|
|
|
|
wrapper: function (toc) {
|
2024-07-14 03:19:35 +00:00
|
|
|
|
return `<nav class="toc" aria-labelledby="toc-heading">${toc}</nav>`;
|
2024-07-14 02:52:19 +00:00
|
|
|
|
},
|
|
|
|
|
});
|
2024-05-06 17:01:15 +00:00
|
|
|
|
eleventyConfig.addPlugin(embedEverything, { add: ['soundcloud'] });
|
|
|
|
|
|
|
|
|
|
// Configure slug filter
|
|
|
|
|
eleventyConfig.addFilter("slug", (str) => {
|
|
|
|
|
if (!str) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return slugify(str, {
|
|
|
|
|
lower: true,
|
|
|
|
|
remove: /["]/g,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-06 18:24:25 +00:00
|
|
|
|
// Configure markdown-it-anchor plugins
|
2024-05-06 17:01:15 +00:00
|
|
|
|
eleventyConfig.setLibrary('md', markdownIt().use(markdownItAnchor))
|
|
|
|
|
const linkAfterHeader = markdownItAnchor.permalink.linkAfterHeader({
|
|
|
|
|
class: "heading-anchor",
|
|
|
|
|
symbol: "<span hidden>#</span>",
|
|
|
|
|
style: "aria-labelledby",
|
|
|
|
|
});
|
|
|
|
|
const markdownItAnchorOptions = {
|
2024-06-04 10:46:40 +00:00
|
|
|
|
level: [2, 3, 4, 5],
|
2024-05-06 17:01:15 +00:00
|
|
|
|
slugify: (str) =>
|
|
|
|
|
slugify(str, {
|
|
|
|
|
lower: true,
|
|
|
|
|
strict: true,
|
|
|
|
|
remove: /["]/g,
|
|
|
|
|
}),
|
|
|
|
|
tabIndex: false,
|
|
|
|
|
permalink(slug, opts, state, idx) {
|
|
|
|
|
state.tokens.splice(idx, 0,
|
|
|
|
|
Object.assign(new state.Token("div_open", "div", 1), {
|
|
|
|
|
// Add class "header-wrapper [h1 or h2 or h3]"
|
|
|
|
|
attrs: [["class", `heading-wrapper ${state.tokens[idx].tag}`]],
|
|
|
|
|
block: true,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
state.tokens.splice(idx + 4, 0,
|
|
|
|
|
Object.assign(new state.Token("div_close", "div", -1), {
|
|
|
|
|
block: true,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
linkAfterHeader(slug, opts, state, idx + 1);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Markdown Overrides */
|
|
|
|
|
let markdownLibrary = markdownIt({
|
|
|
|
|
html: true,
|
2024-05-31 04:47:16 +00:00
|
|
|
|
linkify: true,
|
2024-05-06 17:01:15 +00:00
|
|
|
|
})
|
|
|
|
|
.use(markdownItAnchor, markdownItAnchorOptions)
|
2024-07-18 18:08:10 +00:00
|
|
|
|
.use(markdownItAttribution)
|
|
|
|
|
.use(markdownItAttrs)
|
|
|
|
|
.use(markdownItBracketedSpans)
|
|
|
|
|
.use(markdownItDefList)
|
|
|
|
|
.use(markdownItFootnote);
|
2024-05-17 14:13:56 +00:00
|
|
|
|
|
2024-06-24 05:41:39 +00:00
|
|
|
|
// Configure linkify
|
|
|
|
|
markdownLibrary.linkify.set({ fuzzyLink: false });
|
|
|
|
|
|
2024-05-17 14:13:56 +00:00
|
|
|
|
// Configure markdown-it-footnote
|
|
|
|
|
markdownLibrary.renderer.rules.footnote_block_open = () => (
|
2024-06-13 11:19:40 +00:00
|
|
|
|
'<footer class="footnotes">\n' +
|
2024-05-17 15:58:08 +00:00
|
|
|
|
`<div class="heading-wrapper h2">
|
|
|
|
|
<h2 id="footnotes" class="footnotes__title">Footnotes</h2>
|
|
|
|
|
<a class="heading-anchor" href="#footnotes" aria-labelledby="footnotes"><span hidden="">#</span></a>
|
|
|
|
|
</div>\n` +
|
2024-06-13 11:13:39 +00:00
|
|
|
|
'<ol class="footnotes-list">\n'
|
2024-05-17 14:13:56 +00:00
|
|
|
|
);
|
2024-05-06 17:01:15 +00:00
|
|
|
|
|
2024-06-13 11:04:03 +00:00
|
|
|
|
markdownLibrary.renderer.rules.footnote_anchor = (tokens, idx, options, env, slf) => {
|
|
|
|
|
let id = slf.rules.footnote_anchor_name(tokens, idx, options, env, slf);
|
|
|
|
|
|
|
|
|
|
if (tokens[idx].meta.subId > 0) id += `:${tokens[idx].meta.subId}`;
|
|
|
|
|
|
|
|
|
|
/* ↩ with escape code to prevent display as Apple Emoji on iOS */
|
|
|
|
|
return ` <a aria-label="Back to reference #${id}" href="#fnref${id}" class="footnote-backref">\u21a9\uFE0E</a>`;
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-17 14:44:02 +00:00
|
|
|
|
const renderRules = {
|
2024-06-09 09:34:39 +00:00
|
|
|
|
footnote_caption: ['[', '[<span class="visually-hidden">Footnote #</span>'],
|
2024-06-13 11:19:40 +00:00
|
|
|
|
footnote_block_close: ['section', 'footer'],
|
2024-05-17 14:44:02 +00:00
|
|
|
|
};
|
|
|
|
|
Object.keys(renderRules).map(rule => {
|
|
|
|
|
let defaultRender = markdownLibrary.renderer.rules[rule];
|
|
|
|
|
markdownLibrary.renderer.rules[rule] = (tokens, idx, options, env, self) => {
|
|
|
|
|
return defaultRender(tokens, idx, options, env, self).replace(...renderRules[rule]);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-07 02:26:21 +00:00
|
|
|
|
// Paired shortcode: custom container
|
|
|
|
|
eleventyConfig.addPairedShortcode('container', (children, el, className) => {
|
|
|
|
|
const classMarkup = className ? ` class="${className}"` : "";
|
|
|
|
|
const content = markdownLibrary.render(children);
|
|
|
|
|
return `<${el}${classMarkup}>${content}</${el}>`;
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-09 14:56:31 +00:00
|
|
|
|
// Paired shortcode: image figure and figcaption
|
2024-06-06 14:25:00 +00:00
|
|
|
|
eleventyConfig.addPairedShortcode('imgFigure', (caption, img, alt=caption, enableLazyLoading=true) => {
|
2024-05-07 06:48:11 +00:00
|
|
|
|
const figcaption = markdownLibrary.renderInline(caption);
|
|
|
|
|
return `<figure>
|
2024-06-06 14:25:00 +00:00
|
|
|
|
<img src="${img}" alt="${alt}"${enableLazyLoading ? ' loading="lazy"' : ''}>
|
2024-05-07 06:48:11 +00:00
|
|
|
|
<figcaption>${figcaption}</figcaption>
|
|
|
|
|
</figure>`;
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-19 14:17:53 +00:00
|
|
|
|
// Paired shorcode: Content accordion
|
|
|
|
|
eleventyConfig.addPairedShortcode('accordion', (content, summary) => {
|
|
|
|
|
const summaryMarkup = markdownLibrary.renderInline(summary);
|
2024-05-06 19:51:49 +00:00
|
|
|
|
const contentMarkup = markdownLibrary.render(content);
|
2024-06-19 14:17:53 +00:00
|
|
|
|
return `<details class="content-accordion">
|
|
|
|
|
<summary class="content-accordion__summary">${summaryMarkup}</summary>
|
|
|
|
|
<div class="content-accordion__content">${contentMarkup}</div>
|
2024-05-07 01:53:49 +00:00
|
|
|
|
</details>`;
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-27 16:55:09 +00:00
|
|
|
|
// Paired shorcode: Content warning accordion
|
|
|
|
|
eleventyConfig.addPairedShortcode('contentWarning', (content, warning) => {
|
|
|
|
|
const warningMarkup = markdownLibrary.renderInline(warning);
|
|
|
|
|
const contentMarkup = markdownLibrary.render(content);
|
|
|
|
|
return `<details class="contnet-warning">
|
2024-07-13 12:58:05 +00:00
|
|
|
|
<summary class="contnet-warning__warning"><strong><span aria-hidden="true">⚠️</span> Content Warning:</strong> ${warningMarkup}</summary>
|
2024-05-27 16:55:09 +00:00
|
|
|
|
<div class="contnet-warning__content">${contentMarkup}</div>
|
|
|
|
|
</details>`;
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-06 17:01:15 +00:00
|
|
|
|
/* This is the part that tells 11ty to swap to our custom config */
|
|
|
|
|
eleventyConfig.setLibrary("md", markdownLibrary);
|
|
|
|
|
}
|