-
Notifications
You must be signed in to change notification settings - Fork 3
/
.eleventy.js
151 lines (121 loc) · 6.38 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
module.exports = function(eleventyConfig) {
// static passthroughs - remap to root
eleventyConfig.addPassthroughCopy({ "assets/images/icons/fav/favicon.ico": "/favicon.ico" });
eleventyConfig.addPassthroughCopy({ "assets/images/icons/fav/manifest.json": "/manifest.json" });
eleventyConfig.addPassthroughCopy({ "assets/scripts/service-worker.js": "/service-worker.js" });
eleventyConfig.addPassthroughCopy("assets/images");
eleventyConfig.addPassthroughCopy("assets/scripts");
eleventyConfig.addPassthroughCopy("assets/styles");
eleventyConfig.addPassthroughCopy("admin");
// grab 3rd party dependencies
eleventyConfig.addPassthroughCopy({ "node_modules/mark.js/dist/mark.min.js": "/vendor/scripts/mark.js" });
eleventyConfig.addPassthroughCopy({ "node_modules/gumshoejs/dist/gumshoe.polyfills.min.js": "/vendor/scripts/gumshoe.js" });
eleventyConfig.addPassthroughCopy({ "node_modules/highlightjs/styles": "/vendor/styles/hljs" });
eleventyConfig.addPassthroughCopy({ "node_modules/firacode/distr/woff": "/assets/fonts/" });
eleventyConfig.addPassthroughCopy({ "node_modules/firacode/distr/woff2/": "/assets/fonts/" });
eleventyConfig.addPassthroughCopy({ "node_modules/typeface-noto-serif/files": "/assets/fonts/" });
eleventyConfig.addPassthroughCopy({ "node_modules/typeface-roboto/files": "/assets/fonts/" });
// add filters
eleventyConfig.addFilter("cssmin", require("./plugins/clean-css.js"));
eleventyConfig.addFilter("jsmin", require("./plugins/clean-js.js"));
eleventyConfig.addFilter("dateDisplay", require("./plugins/dates.js"));
eleventyConfig.addFilter("removeHash", html => html.replace(/ #/g, ""));
eleventyConfig.addFilter("removeParen", html => html.replace(/\(.*?\)/g, ""));
eleventyConfig.addFilter("lastDir", str => str.split("/").pop());
eleventyConfig.addFilter("contentTags", tags => tags.filter(t => !["post", "draft"].includes(t)));
eleventyConfig.addFilter("findByName", (arr, findValue) => arr.find(a => a.name === findValue));
eleventyConfig.addFilter("isPostType", tags => tags && tags.some(t => ["post", "draft"].includes(t)));
eleventyConfig.addFilter("isDraft", tags => tags && tags.some(t => t === 'draft'));
eleventyConfig.addFilter("take", (array, n) => array.slice(0, n));
eleventyConfig.addFilter("sortByPostCount", arr => arr.sort((a, b) => (a.posts.length < b.posts.length ? 1 : -1)));
// custom collections
let builder = require("./plugins/builder.js")
eleventyConfig.addCollection("authors", col => builder(col, "author", "name", "summary", "authors", "./pages/authors/"));
eleventyConfig.addCollection("projects", col => builder(col, "project", "name", "summary", "project", "./pages/projects/"));
eleventyConfig.addCollection("teams", col => builder(col, "team", "name", "summary", "team", "./pages/teams/"));
eleventyConfig.addCollection("departments", col => builder(col, "department", "name", "summary", "department", "./pages/departments/"));
eleventyConfig.addCollection("slides", col => {
let presentations = col.getFilteredByTag("presentation")
let allSlides = presentations.map(pres => {
let content = pres.template.frontMatter.content
let pages = content.split(/\r?\n---\r?\n/)
// add metadata to slides level
let slides = pages.map((page, i) => {
let slide = {
href: `/slides/${pres.fileSlug}/${i + 1}/`,
pres: {
title: pres.data.title,
summary: pres.data.summary,
totalPages: pages.length,
fileSlug: pres.fileSlug
},
cur: {
content: page,
html: md.render(page),
curPage: i + 1,
perComplete: `${Math.round(((i + 1) / pages.length) * 100)}%`
}
}
return slide
})
// add previous and next
for (let i = 0; i < slides.length; i++) {
const prev = slides[i - 1];
const next = slides[i + 1];
slides[i].prev = prev;
slides[i].next = next;
}
return slides
})
// flat map all slides
let flatSlides = allSlides.reduce((a, b) => a.concat(b), []);
return flatSlides
});
eleventyConfig.addCollection("drafts", col => col.getFilteredByTag("post").filter(item => item.data.draft));
eleventyConfig.addCollection("published", col => {
let posts = col.getFilteredByTag("post").filter(item => !item.data.draft)
// add previous and next
for (let i = 0; i < posts.length; i++) {
const prevPost = posts[i - 1];
const nextPost = posts[i + 1];
posts[i].data.prevPost = prevPost;
posts[i].data.nextPost = nextPost;
}
return posts;
});
// bundle collection
eleventyConfig.addCollection("bundles", col => {
let script = col.getFilteredByGlob("**/meta/bundle-scripts.js.njk")[0]
let style = col.getFilteredByGlob("**/meta/bundle-styles.css.njk")[0]
return { script, style }
});
// configure syntax highlighting
let md = require("./plugins/customize-markdown.js")()
eleventyConfig.setLibrary("md", md);
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
eleventyConfig.addPairedShortcode("markdown", (content, inline = null) => {
return inline
? md.renderInline(content)
: md.render(content);
});
// add plugins
let pluginTOC = require('eleventy-plugin-nesting-toc');
eleventyConfig.addPlugin(pluginTOC, { tags: ['h2, h3'] });
/* embed tweet plugin setup */
let pluginEmbedTweet = require("eleventy-plugin-embed-tweet")
let tweetEmbedOptions = {
cacheDirectory: 'tweets',
useInlineStyles: false
}
eleventyConfig.addPlugin(pluginEmbedTweet, tweetEmbedOptions);
return {
dir: {
"data": "data",
"includes": "assets",
"layouts": "layouts"
},
// By default markdown files are pre-processing with liquid template engine
// https://www.11ty.io/docs/config/#default-template-engine-for-markdown-files
markdownTemplateEngine: "njk",
};
};