2024-05-06 10:43:37 +00:00
|
|
|
// Installed Plugins
|
2024-04-11 15:32:47 +00:00
|
|
|
const { EleventyRenderPlugin } = require("@11ty/eleventy");
|
2024-04-11 12:18:03 +00:00
|
|
|
const pluginRss = require("@11ty/eleventy-plugin-rss");
|
2024-04-18 12:22:49 +00:00
|
|
|
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
|
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-13 07:00:22 +00:00
|
|
|
const emojiReadTime = require("@11tyrocks/eleventy-plugin-emoji-readtime");
|
2024-04-15 10:21:10 +00:00
|
|
|
const embedEverything = require("eleventy-plugin-embed-everything");
|
2024-04-11 12:16:05 +00:00
|
|
|
|
2024-04-12 17:54:48 +00:00
|
|
|
// Configure slug filter
|
|
|
|
const slugify = require("slugify");
|
|
|
|
|
2024-05-06 10:43:37 +00:00
|
|
|
// Configure markdown-it plugins
|
2024-04-12 17:54:48 +00:00
|
|
|
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-11 12:16:05 +00:00
|
|
|
// Installed Plug-ins
|
2024-04-11 15:32:47 +00:00
|
|
|
eleventyConfig.addPlugin(EleventyRenderPlugin);
|
2024-04-11 12:18:03 +00:00
|
|
|
eleventyConfig.addPlugin(pluginRss);
|
2024-04-18 12:22:49 +00:00
|
|
|
eleventyConfig.addPlugin(eleventyNavigationPlugin);
|
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-13 07:00:22 +00:00
|
|
|
eleventyConfig.addPlugin(emojiReadTime);
|
2024-04-15 10:28:29 +00:00
|
|
|
eleventyConfig.addPlugin(embedEverything, { add: ['soundcloud'] });
|
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,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-05-06 10:43:37 +00:00
|
|
|
// Configure markdown-it plugins
|
|
|
|
eleventyConfig.setLibrary('md', markdownIt().use(markdownItAnchor))
|
2024-04-12 17:54:48 +00:00
|
|
|
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,
|
2024-05-06 10:43:37 +00:00
|
|
|
}),
|
2024-04-12 17:54:48 +00:00
|
|
|
tabIndex: false,
|
|
|
|
permalink(slug, opts, state, idx) {
|
2024-05-06 10:43:37 +00:00
|
|
|
state.tokens.splice(idx, 0,
|
2024-04-12 17:54:48 +00:00
|
|
|
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,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2024-05-06 10:43:37 +00:00
|
|
|
state.tokens.splice(idx + 4, 0,
|
2024-04-12 17:54:48 +00:00
|
|
|
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-06 10:43:37 +00:00
|
|
|
})
|
|
|
|
.use(markdownItAnchor, markdownItAnchorOptions)
|
2024-05-06 12:15:51 +00:00
|
|
|
.use(require("markdown-it-attrs"))
|
2024-05-06 12:26:53 +00:00
|
|
|
.use(require("markdown-it-bracketed-spans"))
|
|
|
|
.use(require("markdown-it-deflist"));
|
2024-04-12 17:54:48 +00:00
|
|
|
|
|
|
|
/* This is the part that tells 11ty to swap to our custom config */
|
|
|
|
eleventyConfig.setLibrary("md", markdownLibrary);
|
|
|
|
|
2024-04-16 09:20:34 +00:00
|
|
|
// Add content categories to a collection
|
|
|
|
eleventyConfig.addCollection("categories", function(collectionApi) {
|
|
|
|
let categories = new Set();
|
2024-04-16 14:07:58 +00:00
|
|
|
let contents = collectionApi.getFilteredByTag('contents');
|
2024-04-16 09:20:34 +00:00
|
|
|
contents.forEach(p => {
|
|
|
|
let cats = p.data.categories;
|
|
|
|
cats.forEach(c => categories.add(c));
|
|
|
|
});
|
|
|
|
return Array.from(categories).sort();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Filter contents by category
|
|
|
|
eleventyConfig.addFilter("filterByCategory", function(contents, cat) {
|
|
|
|
cat = cat.toLowerCase();
|
|
|
|
let result = contents.filter(item => {
|
|
|
|
let cats = item.data.categories.map(c => c.toLowerCase());
|
|
|
|
return cats.includes(cat);
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
2024-04-15 10:21:10 +00:00
|
|
|
// Filter: Format dates
|
|
|
|
const dateOptions = {
|
|
|
|
year: 'numeric',
|
|
|
|
month: 'long',
|
|
|
|
day: 'numeric',
|
|
|
|
};
|
|
|
|
const dateTimeLocale = new Intl.DateTimeFormat("en-GB", dateOptions);
|
|
|
|
eleventyConfig.addFilter("niceDate", function(date) {
|
|
|
|
return dateTimeLocale.format(date);
|
|
|
|
});
|
|
|
|
|
2024-04-16 16:03:41 +00:00
|
|
|
// Filter: Limit number of items displayed
|
|
|
|
eleventyConfig.addFilter("itemLimit", function(array, itemLimit) {
|
|
|
|
return array.slice(0, itemLimit);
|
2024-04-15 10:21:10 +00:00
|
|
|
});
|
|
|
|
|
2024-05-06 14:44:07 +00:00
|
|
|
// Shortcode: <cite> tag
|
|
|
|
eleventyConfig.addShortcode('cite', (str) => `<cite>${str}</cite>`);
|
|
|
|
|
2024-04-06 04:15:14 +00:00
|
|
|
return {
|
|
|
|
dir: {
|
|
|
|
input: "src"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|