-
Notifications
You must be signed in to change notification settings - Fork 18
/
.eleventy.js
118 lines (96 loc) · 3.11 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
const dayjs = require("dayjs");
const fs = require("fs");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const dateFormat = (d, format) => {
return dayjs(d).format(format);
};
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginRss);
/**
* DataDeepMerge, Dynamic Partials, and Strict filters
* are all true by default.
*/
eleventyConfig.setDataDeepMerge(false);
eleventyConfig.setLiquidOptions({
dynamicPartials: false,
strictFilters: false
});
eleventyConfig.addFilter("isFutureDate", (dateObj) => {
return dayjs(dateObj).isAfter(dayjs());
});
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
return dateFormat(dateObj, "YYYY-MM-DD");
});
eleventyConfig.addFilter("readableDate", (dateObj) => {
return dateFormat(dateObj, "ddd, D MMMM YYYY");
});
eleventyConfig.addFilter("formatDate", (dateObj, format) => {
return dateFormat(dateObj, format);
});
eleventyConfig.addFilter("eventsInCity", (events, city) => {
return events.filter((e) => e.city == city);
});
eleventyConfig.addFilter("orphanWrap", (str) => {
if (str) {
let splitSpace = str.split(" ");
let after = "";
if (splitSpace.length > 2) {
after += " ";
let lastWord = splitSpace.pop();
let secondLastWord = splitSpace.pop();
after += `${secondLastWord} ${lastWord}`;
}
return splitSpace.join(" ") + after;
} else {
return str;
}
});
eleventyConfig.addCollection("cities", function(collection) {
return collection.getAllSorted().filter(function(item) {
return item.inputPath.match(/^\.\/src\/cities\/.*\.md$/) !== null;
});
});
eleventyConfig.addCollection("posts", function(collection) {
return collection.getAllSorted().filter(function(item) {
return item.inputPath.match(/^\.\/src\/blog\/.*\.md$/) !== null;
});
});
// This adds the talks as a data source
eleventyConfig.addCollection("talks", function(collection) {
return collection.getAllSorted().filter(function(item) {
return item.inputPath.match(/^\.\/src\/talks\/.*\.md$/) !== null;
});
});
// Watch assets folder for changes
eleventyConfig.addWatchTarget("./src/_assets");
// Copy these assets straight across
eleventyConfig.addPassthroughCopy({ "./src/_assets/misc": "_assets/misc" });
// Copy Node Modules dependencies
eleventyConfig.addPassthroughCopy({
"node_modules/aos/dist/aos.css": "_assets/css/aos.css",
"node_modules/aos/dist/aos.js": "_assets/js/aos.js"
});
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: function(err, browserSync) {
const content_404 = fs.readFileSync("dist/404.html");
browserSync.addMiddleware("*", (req, res) => {
// Provides the 404 content without redirect.
res.write(content_404);
res.end();
});
},
},
});
return {
templateFormats: ["html", "njk", "md", "11ty.js"],
pathPrefix: "/",
passthroughFileCopy: true,
dir: {
input: "src",
output: "dist",
data: "_data",
includes: "_includes",
},
};
};