2024-04-11 12:16:05 +00:00
|
|
|
// Installed Plug-ins
|
2024-04-11 15:32:47 +00:00
|
|
|
const { EleventyRenderPlugin } = require("@11ty/eleventy");
|
2024-04-11 12:16:05 +00:00
|
|
|
const pluginWebc = require("@11ty/eleventy-plugin-webc");
|
2024-04-11 12:18:03 +00:00
|
|
|
const pluginRss = require("@11ty/eleventy-plugin-rss");
|
2024-04-11 12:17:11 +00:00
|
|
|
const metagen = require('eleventy-plugin-metagen');
|
2024-04-12 17:46:51 +00:00
|
|
|
const pluginTOC = require('eleventy-plugin-nesting-toc');
|
2024-04-11 12:16:05 +00:00
|
|
|
|
2024-04-12 17:54:48 +00:00
|
|
|
// Configure slug filter
|
|
|
|
const slugify = require("slugify");
|
|
|
|
|
|
|
|
// Configure markdown-it plug-ins
|
|
|
|
const markdownIt = require("markdown-it");
|
|
|
|
const markdownItAnchor = require("markdown-it-anchor");
|
|
|
|
|
2024-04-06 04:15:14 +00:00
|
|
|
module.exports = function (eleventyConfig) {
|
2024-04-11 12:16:05 +00:00
|
|
|
// Copy files
|
2024-04-06 04:15:14 +00:00
|
|
|
eleventyConfig.addPassthroughCopy("./src/assets/");
|
|
|
|
eleventyConfig.addWatchTarget("./src/assets/");
|
2024-04-06 17:15:00 +00:00
|
|
|
eleventyConfig.addPassthroughCopy({ "./src/assets/feed/": "/" });
|
2024-04-06 04:15:14 +00:00
|
|
|
|
2024-04-11 12:16:05 +00:00
|
|
|
// Installed Plug-ins
|
2024-04-11 15:32:47 +00:00
|
|
|
eleventyConfig.addPlugin(EleventyRenderPlugin);
|
2024-04-11 15:34:28 +00:00
|
|
|
eleventyConfig.addPlugin(pluginWebc, {
|
|
|
|
components: "./src/_includes/**/*.webc",
|
|
|
|
});
|
2024-04-11 12:18:03 +00:00
|
|
|
eleventyConfig.addPlugin(pluginRss);
|
2024-04-11 12:17:11 +00:00
|
|
|
eleventyConfig.addPlugin(metagen);
|
2024-04-12 17:46:51 +00:00
|
|
|
eleventyConfig.addPlugin(pluginTOC, { tags: ['h2', 'h3', 'h4', 'h5'] });
|
2024-04-11 12:16:05 +00:00
|
|
|
|
2024-04-12 17:54:48 +00:00
|
|
|
// Configure slug filter
|
|
|
|
eleventyConfig.addFilter("slug", (str) => {
|
|
|
|
if (!str) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return slugify(str, {
|
|
|
|
lower: true,
|
|
|
|
remove: /["]/g,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Configure markdown-it plug-ins
|
|
|
|
eleventyConfig.setLibrary(
|
|
|
|
'md',
|
|
|
|
markdownIt().use(markdownItAnchor)
|
|
|
|
)
|
|
|
|
const linkAfterHeader = markdownItAnchor.permalink.linkAfterHeader({
|
|
|
|
class: "heading-anchor",
|
|
|
|
symbol: "<span hidden>#</span>",
|
|
|
|
style: "aria-labelledby",
|
|
|
|
});
|
|
|
|
const markdownItAnchorOptions = {
|
|
|
|
level: [1, 2, 3, 4, 5],
|
|
|
|
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,
|
|
|
|
}).use(markdownItAnchor, markdownItAnchorOptions);
|
|
|
|
|
|
|
|
/* This is the part that tells 11ty to swap to our custom config */
|
|
|
|
eleventyConfig.setLibrary("md", markdownLibrary);
|
|
|
|
|
2024-04-06 04:15:14 +00:00
|
|
|
return {
|
|
|
|
dir: {
|
|
|
|
input: "src"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|