-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.eleventy.js
50 lines (44 loc) · 1.4 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
const htmlmin = require("html-minifier");
const yaml = require("js-yaml");
const markdownIt = require("markdown-it");
const markdownItRenderer = new markdownIt();
const { DateTime } = require("luxon");
module.exports = (config) => {
config.addPassthroughCopy({
".src/images": "./images", // images
"./src/admin/config.yml": "./admin/config.yml", // admin config
"./src/static": "/", // static folders/files
});
// filters
config.addFilter("limit", (items, limit) => items.slice(0, limit));
config.addFilter("category", (items, category) => items.filter((item) => item.data.category === category));
config.addFilter("featured", (items) => items.filter((item) => item.data.featured));
config.addFilter("markdown", (data) => markdownItRenderer.render(data));
config.addFilter("readableDate", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat(
"dd LLL yyyy"
);
});
// yaml
config.addDataExtension("yaml", (contents) =>
yaml.load(contents)
);
// minify
config.addTransform("htmlmin", function (content, outputPath) {
if (outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
return {
dir: {
input: "src",
},
htmlTemplateEngine: "njk",
}
};