leilukin-site/eleventy.config.js

85 lines
2.8 KiB
JavaScript
Raw Normal View History

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-07-18 18:08:10 +00:00
import slugify from "slugify";
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
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",
});
// Custom Plugins
2024-07-18 18:08:10 +00:00
eleventyConfig.addPlugin(markdownPlugin);
// 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);
eleventyConfig.addPlugin(emojiReadTime);
// Eleventy bundle plugin
2024-07-18 13:08:32 +00:00
eleventyConfig.addBundle("css");
eleventyConfig.addBundle("js");
// Add content categories to a collection
eleventyConfig.addCollection("categories", function(collectionApi) {
let categories = new Set();
let contents = collectionApi.getFilteredByTag('contents');
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;
});
// 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) {
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-05-06 14:44:07 +00:00
// Shortcode: <cite> tag
eleventyConfig.addShortcode('cite', (str) => `<cite>${str}</cite>`);
// Paired shortcode: Manual heading anchor
eleventyConfig.addPairedShortcode('headingAnchor', (title, hLevel, id=slugify(title)) => {
return `<div class="heading-wrapper h${hLevel}">
<h${hLevel} id="${id}">${title}</h${hLevel}>
<a class="heading-anchor" href="#${id}" aria-labelledby="${id}"><span hidden="">#</span></a>
</div>`;
});
return {
dir: {
input: "src"
}
};
};