2024-05-06 10:43:37 +00:00
|
|
|
// Installed Plugins
|
2024-07-18 18:08:10 +00:00
|
|
|
import pluginRss from "@11ty/eleventy-plugin-rss";
|
|
|
|
import eleventyNavigationPlugin from "@11ty/eleventy-navigation";
|
|
|
|
import metagen from 'eleventy-plugin-metagen';
|
|
|
|
import emojiReadTime from "@11tyrocks/eleventy-plugin-emoji-readtime";
|
2024-04-12 17:54:48 +00:00
|
|
|
|
2024-07-18 18:08:10 +00:00
|
|
|
import slugify from "slugify";
|
2024-06-10 09:29:14 +00:00
|
|
|
|
2024-07-18 18:08:10 +00:00
|
|
|
import markdownPlugin from "./eleventy.config.md.js";
|
|
|
|
|
|
|
|
export default 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-05-22 07:35:10 +00:00
|
|
|
eleventyConfig.addPassthroughCopy({
|
|
|
|
"node_modules/@zachleat/details-utils/details-utils.js": "assets/js/details-utils.js",
|
|
|
|
});
|
2024-04-06 04:15:14 +00:00
|
|
|
|
2024-05-06 17:01:15 +00:00
|
|
|
// Custom Plugins
|
2024-07-18 18:08:10 +00:00
|
|
|
eleventyConfig.addPlugin(markdownPlugin);
|
2024-05-06 17:01:15 +00:00
|
|
|
|
|
|
|
// Installed Plugins
|
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-13 07:00:22 +00:00
|
|
|
eleventyConfig.addPlugin(emojiReadTime);
|
2024-07-18 14:11:18 +00:00
|
|
|
|
|
|
|
// Eleventy bundle plugin
|
2024-07-18 13:08:32 +00:00
|
|
|
eleventyConfig.addBundle("css");
|
2024-07-18 14:11:18 +00:00
|
|
|
eleventyConfig.addBundle("js");
|
2024-04-12 17:54:48 +00:00
|
|
|
|
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);
|
2024-05-10 02:34:12 +00:00
|
|
|
eleventyConfig.addFilter("formatDate", function(date) {
|
2024-04-15 10:21:10 +00:00
|
|
|
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-06-05 23:44:44 +00:00
|
|
|
// Paired shortcode: Manual heading anchor
|
2024-06-10 09:29:14 +00:00
|
|
|
eleventyConfig.addPairedShortcode('headingAnchor', (title, hLevel, id=slugify(title)) => {
|
2024-06-05 23:44:44 +00:00
|
|
|
return `<div class="heading-wrapper h${hLevel}">
|
2024-06-10 09:30:48 +00:00
|
|
|
<h${hLevel} id="${id}">${title}</h${hLevel}>
|
2024-06-05 23:44:44 +00:00
|
|
|
<a class="heading-anchor" href="#${id}" aria-labelledby="${id}"><span hidden="">#</span></a>
|
|
|
|
</div>`;
|
|
|
|
});
|
|
|
|
|
2024-04-06 04:15:14 +00:00
|
|
|
return {
|
|
|
|
dir: {
|
|
|
|
input: "src"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|