-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.eleventy.js
258 lines (223 loc) · 8.39 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
const fs = require("fs");
const util = require("util");
const { optimize } = require("svgo");
const path = require("path");
const markdownIt = require("markdown-it");
const markdownItFootnote = require("markdown-it-footnote");
const dayjs = require("dayjs");
const customParseFormat = require("dayjs/plugin/customParseFormat");
const syntaxHighlightPlugin = require("@11ty/eleventy-plugin-syntaxhighlight");
const Image = require("@11ty/eleventy-img");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const sitemap = require("@quasibit/eleventy-plugin-sitemap");
const contentParser = require("./utils/transforms/contentParser.js");
const htmlMinTransform = require("./utils/transforms/htmlmin.js");
const { findBySlug } = require("./utils/findBySlug");
/**
* Import site configuration
*/
const config = require("./src/_data/config.js");
const pathConfig = require("./src/_data/paths.json");
module.exports = function (eleventyConfig) {
/**
* Removed renaming Passthrough file copy due to issues with incremental
* https://github.com/11ty/eleventy/issues/1299
*/
eleventyConfig.addPassthroughCopy({ static: "/" });
/**
* Create custom data collections
*/
eleventyConfig.addCollection("appearances", require("./collections/appearances"));
eleventyConfig.addCollection("channels", require("./collections/channels"));
eleventyConfig.addCollection("channelsAppearances", require("./collections/channelsAppearances"));
eleventyConfig.addCollection("calendar", require("./collections/calendar"));
eleventyConfig.addCollection("videos", require("./collections/videos"));
eleventyConfig.addCollection("workshops", require("./collections/workshops"));
eleventyConfig.addCollection("posts", require("./collections/posts"));
eleventyConfig.addCollection("emberPosts", require("./collections/ember-posts"));
eleventyConfig.addCollection("elixirPosts", require("./collections/elixirPosts"));
eleventyConfig.addCollection("rustPosts", require("./collections/rustPosts"));
eleventyConfig.addCollection("sveltePosts", require("./collections/sveltePosts"));
eleventyConfig.addCollection("travelPosts", require("./collections/travelPosts"));
eleventyConfig.addCollection("authors", require("./collections/authors"));
eleventyConfig.addCollection("authorsPostsPaged", require("./collections/authorsPostsPaged"));
eleventyConfig.addCollection("tags", require("./collections/tags"));
eleventyConfig.addCollection("tagsPostsPaged", require("./collections/tagsPostsPaged"));
eleventyConfig.addCollection("caseStudies", require("./collections/caseStudies"));
eleventyConfig.addCollection("caseStudiesFeatured", require("./collections/caseStudiesFeatured"));
eleventyConfig.addCollection("twios", require("./collections/twios"));
eleventyConfig.addCollection("memoized", require("./collections/memoized"));
/**
* Add filters
*
* @link https://www.11ty.io/docs/filters/
*/
dayjs.extend(customParseFormat);
eleventyConfig.addFilter("monthDayYear", function (date) {
return dayjs(date).format("MMMM D, YYYY");
});
// robot friendly date format for crawlers
eleventyConfig.addFilter("htmlDate", function (date) {
return dayjs(date).format();
});
eleventyConfig.addFilter("console", function (value) {
return util.inspect(value);
});
eleventyConfig.addFilter("findBySlug", function (slug) {
return findBySlug(slug);
});
eleventyConfig.addFilter("formatTagline", function (tagline) {
return tagline.split("</p>")[0].replace(/<\/?[^>]+(>|$)/g, "");
});
eleventyConfig.addFilter("stripHTML", value => {
return value.replace(/(<([^>]+)>)/gi, "");
});
const mdRender = new markdownIt({
html: true,
breaks: false,
linkify: true,
}).use(markdownItFootnote);
eleventyConfig.addFilter("markdown", function (value) {
if (value) {
return mdRender.render(value);
}
return "";
});
eleventyConfig.setLibrary("md", mdRender);
eleventyConfig.addFilter("filterByAttribute", (array, attribute, value) => {
return array.filter(element => element.data[attribute] === value);
});
eleventyConfig.addFilter("limit", (array, limit) => {
return array.slice(0, limit);
});
eleventyConfig.addFilter("getMorePosts", function (array, post) {
return array
.filter(element => element.inputPath !== post.inputPath)
.map(el => {
return el.fileSlug;
});
});
eleventyConfig.addFilter("getCollectionKeys", function (collection) {
return Object.keys(collection);
});
eleventyConfig.addLiquidFilter("dateToRfc3339", pluginRss.dateToRfc3339);
eleventyConfig.addLiquidFilter("dateToRfc822", pluginRss.dateToRfc822);
eleventyConfig.addFilter("urlExists", (url, collection) => {
return Boolean(collection?.find(({ page }) => page.url === url));
});
eleventyConfig.addFilter("future", collection => {
return collection.filter(item => {
if (Number.isNaN(Date.parse(item.endDate))) return console.log("Workshop has invalid date!");
return Date.parse(item.endDate) > new Date();
});
});
/*
* Add Transforms
*
* @link https://www.11ty.io/docs/config/#transforms
*/
// Parse the page HTML content and perform some manipulation
eleventyConfig.addTransform("contentParser", contentParser);
if (process.env.ELEVENTY_ENV === "production") {
// Minify HTML when building for production
eleventyConfig.addTransform("htmlmin", htmlMinTransform);
}
/**
* Add Plugins
* @link https://github.com/11ty/eleventy-plugin-rss
* @link https://github.com/11ty/eleventy-plugin-syntaxhighlight
* @link https://github.com/okitavera/eleventy-plugin-pwa
*/
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(syntaxHighlightPlugin);
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(sitemap, {
sitemap: {
hostname: config.url,
},
});
/**
* Add Shortcodes
*/
const now = new Date();
eleventyConfig.addShortcode("copyrightYear", function () {
return `${now.getFullYear()}`;
});
eleventyConfig.addShortcode(
"image",
function (imgPath, alt, sizes, loading, className, sizesArray) {
let url = "./static" + imgPath;
const fileType = path.extname(imgPath).replace(".", "");
const directory = path.dirname(imgPath);
let formats = ["webp", ...(fileType !== "gif" ? [fileType] : [])];
if (!sizesArray) {
sizesArray = [720, 1024, 1440];
}
const options = {
svgShortCircuit: true,
widths: sizesArray,
formats,
urlPath: directory,
outputDir: "./dist/" + directory,
filenameFormat: function (id, src, width, format) {
const extension = path.extname(imgPath);
const name = path.basename(imgPath, extension);
return `${name}@${width}.${format}`;
},
};
let stats = Image.statsSync(url, options);
Image(url, options);
let imageAttributes = {
class: className,
alt,
sizes: sizes ? sizes : "100vw",
loading: loading,
};
return Image.generateHTML(stats, imageAttributes);
}
);
eleventyConfig.addShortcode("svg", svgPath => {
const svgData = fs.readFileSync("./static/assets/images" + svgPath, "utf8");
const response = optimize(svgData, {
plugins: [
{
name: "preset-default",
params: {
overrides: {
removeViewBox: false,
},
},
},
],
});
return response.data.replace("<svg", `<svg focusable="false" role="presentation"`);
});
eleventyConfig.addShortcode("mastodonHandleUrl", handle => {
const [user, server] = handle.split("@").filter(Boolean);
return `https://${server}/@${user}`;
});
eleventyConfig.setServerOptions({
watch: ["./dist/assets/css/*.css", "./dist/assets/js/*.js"],
});
/*
* Disable use gitignore for avoiding ignoring of /bundle folder during watch
* https://www.11ty.dev/docs/ignores/#opt-out-of-using-.gitignore
*/
eleventyConfig.setUseGitIgnore(false);
/**
* Eleventy configuration object
*/
return {
dir: {
input: pathConfig.src,
includes: pathConfig.includes,
layouts: `${pathConfig.includes}/layouts`,
output: pathConfig.output,
},
passthroughFileCopy: true,
templateFormats: ["njk", "md"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
};
};