forked from GemCopeland/personal-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
128 lines (110 loc) · 3.53 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
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,
});
// Add plugin
eleventyConfig.addPlugin(pluginRss);
// Add profile collection so that we can access this outside of homepage
// TODO Surely there is a better way to do this? Possible to create a data file that pulls from home.md?
eleventyConfig.addCollection("profile", (collection) => {
return collection.getAll().filter((item) => {
return item.data.section == "home";
});
});
// 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", (code) => {
let minified = UglifyJS.minify(code);
if (minified.error) {
console.log("UglifyJS error: ", minified.error);
return code;
}
return minified.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?:|)\/\//, "");
});
// Create Posts collection
eleventyConfig.addCollection("posts", (collection) => {
const livePosts = (p) => p.date <= now;
return collection
.getFilteredByGlob("./src/posts/*.md")
.filter(livePosts)
.reverse();
});
// Create activityCurrent collection
eleventyConfig.addCollection("activityCurrent", (collection) => {
return collection
.getFilteredByGlob("./src/activity/*.md")
.filter((item) => {
return item.data.dateEnd >= now;
})
.reverse();
});
// Create activityPast collection
eleventyConfig.addCollection("activityPast", (collection) => {
return collection
.getFilteredByGlob("./src/activity/*.md")
.filter((item) => {
return item.data.dateEnd < now;
})
.reverse();
});
// Markdown
let markdownIt = require("markdown-it");
let 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": "/" });
eleventyConfig.addPassthroughCopy({ "src/_includes/assets/pdf": "pdf" });
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",
},
};
};