-
Notifications
You must be signed in to change notification settings - Fork 2
/
eleventy.config.js
214 lines (180 loc) · 4.5 KB
/
eleventy.config.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
const moment = require("moment");
const defaultCssPath = "/soul-class-style-badass.css";
const pluginRss = require("@11ty/eleventy-plugin-rss");
const { EleventyI18nPlugin } = require("@11ty/eleventy");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: "en",
});
eleventyConfig.addCollection(
"mostRecentNowPost",
function(collection) {
const postsTaggedNow = collection.getFilteredByTag("now");
const mostRecentPostTaggedNow = postsTaggedNow[postsTaggedNow.length - 1];
return mostRecentPostTaggedNow;
}
);
eleventyConfig.addCollection(
"nowPageUpdates",
function(collection) {
const postsTaggedNow = collection.getFilteredByTag("now");
return postsTaggedNow;
}
);
eleventyConfig.addCollection(
"atomFeed",
function(collection) {
const postsTaggedBlog = collection.getFilteredByTag("posts");
const postsTaggedNow = collection.getFilteredByTag("now");
postsTaggedBlog.push(postsTaggedNow[postsTaggedNow.length - 1]);
return postsTaggedBlog;
}
);
// Like blogPostsByYear only excluding any featured/interviews/conference talks
eleventyConfig.addCollection(
"blogPostsByYear",
function(collection) {
/*
We assume collection.getFilteredByTag is sorted date ascending.
Return an array of objects containing `year` and `data` array of posts
sorted descending, example:
[
{
year: 1984,
data: [
posts here
]
}, ...
]
*/
const postsTaggedBlog = collection.getFilteredByTag("posts");
const newCollection = [];
let currentPostYearInCollection;
for (let post of postsTaggedBlog) {
const postYear = new Date(post.date).getUTCFullYear();
if (postYear !== currentPostYearInCollection) {
newCollection.unshift({
year: postYear,
data: []
});
currentPostYearInCollection = postYear;
}
newCollection[0].data.unshift(post);
}
return newCollection;
}
);
eleventyConfig.addCollection(
"otherPostsByYear",
function(collection) {
/*
We assume collection.getFilteredByTag is sorted date ascending.
Return an array of objects containing `year` and `data` array of posts
sorted descending, example:
[
{
year: 1984,
data: [
posts here
]
}, ...
]
*/
const postsTaggedBlog = collection.getFilteredByTag("posts");
const newCollection = [];
let currentPostYearInCollection;
for (let post of postsTaggedBlog) {
if (
post.data.tags.includes("featured") ||
post.data.tags.includes("conferenceTalk") ||
post.data.tags.includes("featuredInterview")
) {
continue;
}
const postYear = new Date(post.date).getUTCFullYear();
if (postYear !== currentPostYearInCollection) {
newCollection.unshift({
year: postYear,
data: []
});
currentPostYearInCollection = postYear;
}
newCollection[0].data.unshift(post);
}
return newCollection;
}
);
eleventyConfig.addNunjucksFilter(
"json",
function(value) {
return JSON.stringify(value);
}
);
eleventyConfig.addHandlebarsHelper(
"moment",
function(date, format) {
return moment(date).format(format);
}
);
eleventyConfig.addHandlebarsHelper(
"reverseArray",
function(arr) {
return [...arr].reverse();
}
);
/*
If `css` defined in front matter, an array is needed by Handlebars template.
`css` may be a single item and therefore gets parsed as a string. Need to return it as an 1-element array.
If "default" is a value, replace with path to default CSS file.
*/
eleventyConfig.addHandlebarsHelper(
"cssHelper",
function(stylesheet) {
if (stylesheet === "default") {
return defaultCssPath;
} else {
return stylesheet;
}
}
);
eleventyConfig.addPassthroughCopy("functions");
eleventyConfig.addPassthroughCopy("scripts");
eleventyConfig.addPassthroughCopy("campaigns");
eleventyConfig.addPassthroughCopy("site/**/*.js");
eleventyConfig.addPassthroughCopy("site/_headers");
eleventyConfig.addPassthroughCopy("site/_redirects");
eleventyConfig.addPlugin(pluginRss);
return {
templateFormats: [
"css",
"hbs",
"html",
"json",
"jpg",
"m4v",
"md",
"mp4",
"njk",
"otf",
"pdf",
"png",
"svg",
"ttf",
"txt",
"webmanifest",
"webm",
"webp",
"woff",
"woff2",
"xml"
],
markdownTemplateEngine: "liquid",
htmlTemplateEngine: "hbs",
passthroughFileCopy: true,
dir: {
includes: "../eleventy-includes",
input: "site",
output: "dist"
}
}
};