-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.eleventy.js
52 lines (43 loc) · 1.66 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
const { DateTime } = require("luxon");
const { JSDOM } = require("jsdom");
const pluginRss = require("@11ty/eleventy-plugin-rss");
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("src/styles.css");
eleventyConfig.addPassthroughCopy("src/main.js");
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addCollection("pages", function (collectionApi) {
return collectionApi.getFilteredByGlob("src/sections/*.md").sort((a, b) => a.data.order - b.data.order);
});
eleventyConfig.addCollection("blog", function (collectionApi) {
return collectionApi.getFilteredByGlob("src/blog/*.md").sort((a, b) => {
return b.date - a.date;
});
});
eleventyConfig.addFilter("date", (dateObj, format = "yyyy-MM-dd") => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat(format);
});
eleventyConfig.addTransform("lazyloadImages", function (content, outputPath) {
if (outputPath && outputPath.endsWith(".html")) {
const dom = new JSDOM(content);
const images = dom.window.document.querySelectorAll("img");
images.forEach((img) => {
if (!img.hasAttribute("loading")) {
img.setAttribute("loading", "lazy");
}
});
return dom.serialize();
}
return content;
});
return {
dir: {
input: "src",
includes: "_includes",
output: "_site"
},
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
templateFormats: ["md", "njk"]
};
};