-
Notifications
You must be signed in to change notification settings - Fork 8
/
.eleventy.js
133 lines (109 loc) · 3.56 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const { DateTime } = require("luxon");
const CleanCSS = require("clean-css");
const UglifyJS = require("uglify-es");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const now = new Date();
module.exports = (eleventyConfig) => {
eleventyConfig.setBrowserSyncConfig({ notify: true });
eleventyConfig.setDataDeepMerge(false);
eleventyConfig.setLiquidOptions({ strictFilters: false, dynamicPartials: false });
// Add plugin
eleventyConfig.addPlugin(pluginRss);
// Add excerpts
eleventyConfig.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "<!-- more -->",
});
// Minify CSS
eleventyConfig.addFilter("cssmin", (code) => {
return new CleanCSS({}).minify(code).styles;
});
// Minify JS
eleventyConfig.addFilter("jsmin", (original) => {
const { error, code, warnings } = UglifyJS.minify(original);
if (error) {
console.log("UglifyJS error: ", error);
return original;
}
if (warnings) {
console.log("UglifyJS warnings: ", warnings);
}
return code;
});
// Date formatting
eleventyConfig.addFilter("machineDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat("yyyy-MM-dd");
});
eleventyConfig.addFilter("readableDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy");
});
eleventyConfig.addFilter("activityDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat("MM.yyyy");
});
eleventyConfig.addFilter("activityYear", (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat("yyyy");
});
eleventyConfig.addFilter("cleanUrl", (url) => {
return url.replace(/^(https?:|)\/\//, "");
});
eleventyConfig.addFilter("debug", (obj) => {
console.log('debug', obj);
return `debug: ${obj?.toString() || obj}`
}
);
// Add profile collection so that we can access this outside of homepage
eleventyConfig.addCollection("profile", (collection) => {
return collection.getFilteredByGlob('**/pages/home.md')[0];
});
// Create Posts collection
eleventyConfig.addCollection("posts", (collection) => {
return collection
.getFilteredByGlob('**/posts/*.md')
.filter((p) => p.date <= now)
.reverse();
});
// Create activityCurrent collection
eleventyConfig.addCollection("activityCurrent", (collection) => {
return collection
.getFilteredByGlob('**/activity/*.md')
.filter((item) => item.data.dateEnd >= now)
.reverse();
});
// Create activityPast collection
eleventyConfig.addCollection("activityPast", (collection) => {
return collection
.getFilteredByGlob('**/activity/*.md')
.filter((item) => item.data.dateEnd < now)
.reverse();
});
// Markdown
const markdownIt = require("markdown-it");
const options = {
html: true,
breaks: true,
linkify: true,
typographer: true,
};
eleventyConfig.setLibrary("md", markdownIt(options));
eleventyConfig.addNunjucksFilter("markdownify", (markdownString) =>
markdownIt(options).render(markdownString)
);
// Copy the fonts
eleventyConfig.addPassthroughCopy({ "src/_includes/assets/fonts": "fonts" });
// Copy the favicon contents
eleventyConfig.addPassthroughCopy({ "src/_includes/assets/favicon": "/" });
return {
templateFormats: ["md", "njk", "html", "liquid", "woff", "woff2"],
pathPrefix: "/",
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
// passthroughFileCopy: true,
dir: {
input: "src",
includes: "_includes",
data: "_data",
output: "_dist",
},
};
};