This repository has been archived by the owner on Sep 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
86 lines (70 loc) · 2.26 KB
/
.eleventy.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require("dotenv").config();
const pluginRss = require("@11ty/eleventy-plugin-rss");
const eleventyHelmetPlugin = require("eleventy-plugin-helmet");
const markdownIt = require("markdown-it");
const mdFigures = require("markdown-it-image-figures");
const mdPrism = require("markdown-it-prism");
const htmlmin = require("html-minifier");
const markdownItAttrs = require("markdown-it-attrs");
const markdownItRenderer = new markdownIt({ html: true })
.use(markdownItAttrs)
.use(mdFigures, {
figcaption: true,
})
.use(mdPrism);
const image = require("./utils/image");
module.exports = function (eleventyConfig) {
eleventyConfig.setTemplateFormats(["html", "liquid", "njk", "md"]);
eleventyConfig.setDataDeepMerge(true);
eleventyConfig.addPlugin(eleventyHelmetPlugin);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addFilter("markdownify", (str) =>
markdownItRenderer.render(str),
);
eleventyConfig.addFilter("markdownifyInline", (str) =>
markdownItRenderer.renderInline(str),
);
eleventyConfig.addFilter("startsWith", (string, arg) =>
string.startsWith(arg),
);
eleventyConfig.addFilter(
"activeUrl",
(desiredUrl, pageUrl, activeClass, inactiveClass) =>
desiredUrl === pageUrl ? activeClass : inactiveClass,
);
eleventyConfig.addFilter("getAuthor", (authorKey) =>
require(`./site/_data/authors/${authorKey}.json`),
);
eleventyConfig.addShortcode("image", async (src, alt, klass = "") =>
image(src, alt, klass, false),
);
eleventyConfig.addShortcode("responsiveImage", async (src, alt, klass = "") =>
image(src, alt, klass, true),
);
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
if (outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});
eleventyConfig.setLibrary("md", markdownItRenderer);
eleventyConfig.setLiquidOptions({
dynamicPartials: false,
strictFilters: false,
});
return {
dir: {
input: "site/",
data: "_data",
includes: "_includes",
output: "_output",
},
htmlTemplateEngine: "liquid",
markdownTemplateEngine: "liquid",
};
};