-
Notifications
You must be signed in to change notification settings - Fork 3
/
.eleventy.js
80 lines (69 loc) · 2.08 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
const {
DateTime
} = require("luxon");
const {
minify
} = require("terser");
const markdownIt = require("markdown-it");
const CleanCSS = require("clean-css");
const htmlmin = require("html-minifier");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("source/static");
eleventyConfig.addPassthroughCopy("source/notes/**/*.{jpg,jpeg,png}");
eleventyConfig.addCollection("log", function (collectionApi) {
return collectionApi.getFilteredByGlob("source/logbook/**/*.md").sort(function (a, b) {
return a.date - b.date;
});
});
eleventyConfig.addCollection("notes", function (collectionApi) {
return collectionApi.getFilteredByGlob("source/notes/**/*.md").sort(function (a, b) {
return a.date - b.date;
});
});
eleventyConfig.addFilter("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_MED);
});
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
if (outputPath && outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
eleventyConfig.addFilter("cssmin", function (code) {
return new CleanCSS({}).minify(code).styles;
});
eleventyConfig.addNunjucksAsyncFilter("jsmin", async function (code, callback) {
try {
const minified = await minify(code);
callback(null, minified.code);
} catch (err) {
console.error("Terser error: ", err);
// Fail gracefully.
callback(null, code);
}
});
eleventyConfig.setLibrary("md", markdownIt({
html: true,
breaks: true,
linkify: true
}).use(require('markdown-it-figure')));
return {
dir: {
input: "source/",
output: "dist",
includes: "_includes",
layouts: "_layouts"
},
templateFormats: ["html", "md", "njk"],
htmlTemplateEngine: "njk",
passthroughFileCopy: true
};
};