-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
66 lines (57 loc) · 1.88 KB
/
eleventy.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import * as path from "node:path";
import { EleventyHtmlBasePlugin as pluginHtmlBase } from "@11ty/eleventy";
import pluginNavigation from "@11ty/eleventy-navigation";
import { absoluteUrl } from "@11ty/eleventy-plugin-rss";
import pluginVite from "@11ty/eleventy-plugin-vite";
import Image from "@11ty/eleventy-img";
import htmlnano from "htmlnano";
/**
* @param {import("@11ty/eleventy").UserConfig} config
*/
export default function (config) {
config.addPlugin(pluginHtmlBase);
config.addPlugin(pluginNavigation);
config.addPlugin(pluginVite);
config.addNunjucksFilter("absoluteUrl", absoluteUrl);
config.addNunjucksFilter("sourceUrl", (url) =>
path.join(import.meta.dirname, "src", url),
);
config.addNunjucksAsyncShortcode("svgContents", async (src) => {
const metadata = await Image(src, {
formats: ["svg"],
dryRun: true,
});
return metadata.svg[0].buffer.toString("utf-8");
});
config.addTransform("htmlnano", async function (content) {
const { outputPath } = this.page;
if (!outputPath || !outputPath.endsWith(".html")) {
return content;
}
const result = await htmlnano.process(content, {
minifyJs: false,
minifyCss: false,
minifySvg: false,
removeComments: "safe",
collapseWhitespace: "conservative",
});
return result.html;
});
config.addLayoutAlias("base", "layouts/base.html");
config.addLayoutAlias("empty", "layouts/empty.html");
config.addPassthroughCopy("src/manifest.webmanifest");
config.addPassthroughCopy("src/assets/images");
config.addPassthroughCopy("src/assets/scripts");
config.addPassthroughCopy("src/assets/styles");
config.addWatchTarget("src/assets");
config.setDataDeepMerge(true);
return {
dir: {
input: "src",
output: "build",
},
templateFormats: ["html", "md"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
};
}