1import htmlmin from "html-minifier";
2import * as sass from "sass";
3import path from "path";
4import markdownit from "markdown-it";
5const md = markdownit();
6
7export default function (eleventyConfig) {
8 eleventyConfig.addPassthroughCopy("favicon.png");
9 eleventyConfig.addPassthroughCopy(".well-known/*");
10
11 eleventyConfig.addTemplateFormats("scss");
12 eleventyConfig.addExtension("scss", {
13 outputFileExtension: "css",
14 compile: async function (inputContent, inputPath) {
15 let result = sass.compileString(inputContent, {
16 loadPaths: [path.dirname(inputPath)],
17 style: "compressed",
18 });
19 return async () => {
20 return result.css;
21 };
22 },
23 });
24
25 eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
26 if (outputPath && outputPath.endsWith(".html")) {
27 return htmlmin.minify(content, {
28 useShortDoctype: true,
29 removeComments: true,
30 collapseWhitespace: true,
31 collapseInlineTagWhitespace: false,
32 });
33 }
34 return content;
35 });
36
37 eleventyConfig.addNunjucksFilter("markdown", function (value) {
38 return md.render(value);
39 });
40
41 eleventyConfig.addNunjucksFilter("format_date", function (value) {
42 return new Date(value).toISOString().slice(0, 16).replace("T", " ");
43 });
44
45 eleventyConfig.addNunjucksFilter("truncate", function (value, length = 300) {
46 return value.slice(0, length);
47 });
48
49 eleventyConfig.addNunjucksFilter("getrkey", function (value) {
50 return value.slice(value.lastIndexOf("/") + 1);
51 });
52}