-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
83 lines (70 loc) · 2.35 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
const path = require("path");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const sanitizeHTML = require("sanitize-html");
const dateFilter = require("./src/filters/date-filter");
const webmentionsFilter = require("./src/filters/webmentions");
const Image = require("@11ty/eleventy-img");
module.exports = (config) => {
config.addPassthroughCopy("src/img");
// plugins
config.addPlugin(pluginRss, {
posthtmlRenderOptions: {
closingSingleTag: "default", // opt-out of <img/>-style XHTML single tags
},
});
// filters
config.addFilter("dateFilter", dateFilter);
config.addFilter("webmentionsForUrl", webmentionsFilter);
config.addFilter("isNan", (value) => {
return isNaN(value);
});
// watch targets
config.addWatchTarget("./src/blog/*");
config.addWatchTarget("./src/css/*");
// collections
config.addCollection("posts", (collection) => {
return [
...collection.getFilteredByGlob("./src/blog/posts/*.md"),
].reverse();
});
config.addCollection("weeknotes", (collection) => {
return [
...collection.getFilteredByGlob("./src/blog/weeknotes/*.md"),
].reverse();
});
config.setUseGitIgnore(false);
async function imageShortcode(src, cls, alt, sizes, pageURL) {
const imgPath = pageURL ? pageURL : "img";
const metadata = await Image(src, {
widths: [200, 300, 400],
formats: ["jpeg"],
urlPath: "/img/",
outputDir: "dist/" + imgPath,
filenameFormat: function (id, src, width, format, options) {
const extension = path.extname(src);
const name = path.basename(src, extension);
return `${name}-${width}w.${format}`;
},
});
const imageAttributes = {
class: cls,
alt,
sizes,
loading: "lazy",
decoding: "async",
};
return Image.generateHTML(metadata, imageAttributes, {
whitespaceMode: "inline",
});
}
config.addNunjucksAsyncShortcode("image", imageShortcode);
return {
markdownTemplateEngine: "njk",
dataTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dir: {
input: "src",
output: "dist",
},
};
};