gil.ink/.eleventy.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-04-30 02:44:05 -04:00
import { RenderPlugin, IdAttributePlugin } from "@11ty/eleventy";
2025-02-06 21:51:23 -05:00
import eleventyNavigationPlugin from "@11ty/eleventy-navigation";
import markdownIt from "markdown-it";
import markdownItFootnote from "markdown-it-footnote";
2025-02-19 03:03:13 -05:00
import { DateTime } from "luxon";
2025-02-06 21:51:23 -05:00
2025-02-18 15:12:10 -05:00
export default function (eleventyConfig) {
const MARKDOWN_OPTIONS = {
html: true,
breaks: true,
linkify: true,
typographer: true,
};
2025-05-18 13:17:26 -04:00
let md = markdownIt(MARKDOWN_OPTIONS).use(markdownItFootnote);
2025-02-06 21:51:23 -05:00
// Libraries
eleventyConfig.setLibrary("md", md);
// Plugins
2025-04-30 02:44:05 -04:00
eleventyConfig.addPlugin(RenderPlugin);
eleventyConfig.addPlugin(IdAttributePlugin);
2025-02-06 21:51:23 -05:00
eleventyConfig.addPlugin(eleventyNavigationPlugin);
2025-02-19 03:03:13 -05:00
// Filters
2025-05-18 13:17:26 -04:00
eleventyConfig.addFilter("formatDate", function (date, format) {
return DateTime.fromJSDate(date).toFormat(format);
2025-05-16 21:16:21 -04:00
});
2025-05-18 13:17:26 -04:00
eleventyConfig.addFilter("formatDateRel", function (date) {
return DateTime.fromJSDate(date).toRelative();
});
eleventyConfig.addFilter("md", function (content = "") {
return md.render(content);
2025-02-19 03:03:13 -05:00
});
2025-05-18 13:17:26 -04:00
eleventyConfig.addFilter("mdInline", function (content = "") {
2025-04-28 01:49:10 -04:00
return md.renderInline(content);
});
2025-02-19 03:03:13 -05:00
2025-02-06 21:51:23 -05:00
// Passthrough copies
2025-02-18 15:12:10 -05:00
["src/assets"].forEach((path) => {
eleventyConfig.addPassthroughCopy(path);
});
2025-04-30 02:44:05 -04:00
2025-05-18 13:17:26 -04:00
// Watch targets
2025-02-06 21:51:23 -05:00
eleventyConfig.addWatchTarget("./src/assets/css");
2025-05-18 13:17:26 -04:00
// Frontmatter parsing
eleventyConfig.setFrontMatterParsingOptions({ excerpt: true });
// COLLECTIONS
////// Journal categories
eleventyConfig.addCollection("categories", function (collectionApi) {
let categories = new Set();
let posts = collectionApi.getFilteredByTag("post");
posts.forEach((p) => {
let cats = p.data.categories;
cats.forEach((c) => categories.add(c));
});
return Array.from(categories);
});
2025-02-06 21:51:23 -05:00
return {
dir: {
2025-02-19 03:03:13 -05:00
input: "src",
output: "public",
includes: "_includes",
layouts: "_layouts",
2025-02-06 21:51:23 -05:00
},
};
}