-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
58 lines (51 loc) · 1.87 KB
/
.eleventy.js
File metadata and controls
58 lines (51 loc) · 1.87 KB
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
const { DateTime } = require("luxon");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor")
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight")
const rss = require("@11ty/eleventy-plugin-rss");
const htmlmin = require("html-minifier")
const cleanCss = require("clean-css");
module.exports = (eleventyConfig) => {
// plugins
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(rss);
// passthrough
eleventyConfig.addPassthroughCopy("css");
eleventyConfig.addPassthroughCopy("img");
eleventyConfig.addPassthroughCopy("robots.txt");
// date formatters
eleventyConfig.addFilter("readableDate", (date) => {
return DateTime.fromJSDate(date, { zone: "utc" }).toLocaleString(DateTime.DATE_FULL);
});
eleventyConfig.addFilter("htmlDateString", (date) => {
return DateTime.fromJSDate(date, { zone: "utc" }).toISODate();
});
// inline css
eleventyConfig.addFilter("cssmin", (code) => {
return new cleanCss({}).minify(code).styles;
});
// year shortcode
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
// markdown rendering: anchors for all headings
const markdownLibrary = markdownIt({
html: true,
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
class: "anchor-link",
placement: "after",
symbol: "#",
}),
level: [1, 2, 3],
});
eleventyConfig.setLibrary("md", markdownLibrary);
// minify html
eleventyConfig.addTransform("htmlmin", (content, outputPath) => {
if (outputPath.endsWith(".html")) {
return htmlmin.minify(content, {
collapseWhitespace: true,
removeComments: true,
});
}
return content;
});
};