-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
188 lines (167 loc) · 5.12 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
const pluginRss = require("@11ty/eleventy-plugin-rss")
const pluginNavigation = require("@11ty/eleventy-navigation")
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight")
const pluginSvgSprite = require("eleventy-plugin-svg-sprite")
const pluginPageAssets = require("eleventy-plugin-page-assets")
const markdownIt = require("markdown-it")
const markdownItFootnote = require("markdown-it-footnote")
const embedEverything = require("eleventy-plugin-embed-everything")
const lodash = require("lodash")
const filters = require("./utils/filters.js")
const transforms = require("./utils/transforms.js")
const shortcodes = require("./utils/shortcodes.js")
const IS_PRODUCTION = process.env.ELEVENTY_ENV === "production"
const CONTENT_GLOBS = {
work: "src/work/**/*.md",
writing: "src/writing/**/*.md",
media: "*.jpg|*.png|*.gif|*.mp4|*.webp|*.webm"
}
module.exports = function (config) {
// Plugins
config.addPlugin(syntaxHighlight)
config.addPlugin(pluginRss)
config.addPlugin(pluginNavigation)
config.addPlugin(pluginSvgSprite, {
path: "./src/assets/icons",
svgSpriteShortcode: "iconsprite"
})
config.addPlugin(pluginPageAssets, {
mode: "directory",
postsMatching: ["src/work/*/*.md", "src/writing/*/*.md"],
assetsMatching: CONTENT_GLOBS.media,
silent: true
})
config.addPlugin(embedEverything)
// Filters
Object.keys(filters).forEach((filterName) => {
config.addFilter(filterName, filters[filterName])
})
// Transforms
Object.keys(transforms).forEach((transformName) => {
config.addTransform(transformName, transforms[transformName])
})
// Shortcodes
Object.keys(shortcodes).forEach((shortcodeName) => {
config.addShortcode(shortcodeName, shortcodes[shortcodeName])
})
// Asset Watch Targets
config.addWatchTarget("./src/assets")
// Markdown
config.setLibrary(
"md",
markdownIt({
html: true,
breaks: true,
linkify: true,
typographer: true
}).use(markdownItFootnote)
)
// Layouts
config.addLayoutAlias("base", "base.njk")
config.addLayoutAlias("post", "post.njk")
// Pass-through files
config.addPassthroughCopy("src/robots.txt")
config.addPassthroughCopy("src/site.webmanifest")
config.addPassthroughCopy("src/assets/images")
config.addPassthroughCopy("src/assets/fonts")
config.addPassthroughCopy({ static: "/" })
// Deep-Merge
config.setDataDeepMerge(true)
// Collections: Works
config.addCollection("works", function (collection) {
return collection
.getFilteredByGlob(CONTENT_GLOBS.work)
.filter((item) => item.data.permalink !== false)
.filter((item) => !(item.data.draft && IS_PRODUCTION))
.sort((a, b) => b.date - a.date)
})
// Collect all tags from works
let workTagsSet = new Set()
config.addCollection("workTags", function (collection) {
collection
.getFilteredByGlob(CONTENT_GLOBS.work)
.filter((item) => !(item.data.draft && IS_PRODUCTION))
.forEach((item) => {
if (item.data.tags) {
item.data.tags.forEach((tag) => workTagsSet.add(tag))
}
})
return Array.from(workTagsSet)
})
// Collections: Works by year
config.addCollection("worksbyyear", (collection) => {
return lodash
.chain(collection.getFilteredByGlob(CONTENT_GLOBS.work))
.filter(
(item) =>
item.data.selected || !(item.data.draft && IS_PRODUCTION)
)
.groupBy((works) => works.date.getFullYear())
.toPairs()
.reverse()
.value()
})
// Collections: Selected Works
config.addCollection("selected", function (collection) {
return collection
.getFilteredByGlob(CONTENT_GLOBS.work)
.filter((item) => item.data.selected)
.sort((a, b) => b.date - a.date)
})
// Collections: Writing
config.addCollection("writing", function (collection) {
return collection
.getFilteredByGlob(CONTENT_GLOBS.writing)
.filter((item) => item.data.permalink !== false)
.filter((item) => !(item.data.draft && IS_PRODUCTION))
.sort((a, b) => b.date - a.date)
})
// Collect all tags from writing
let writingTagsSet = new Set()
config.addCollection("writingTags", function (collection) {
collection
.getFilteredByGlob(CONTENT_GLOBS.writing)
.filter((item) => !(item.data.draft && IS_PRODUCTION))
.forEach((item) => {
if (item.data.tags) {
item.data.tags.forEach((tag) => writingTagsSet.add(tag))
}
})
return Array.from(writingTagsSet)
})
// Collections: Writing Categories
config.addCollection("writingCategories", function (collection) {
let categorySet = new Set()
collection.getAll().forEach((item) => {
if (item.data.category) {
item.data.category.forEach((category) =>
categorySet.add(category)
)
}
})
return Array.from(categorySet)
})
// Collections: Writing by year
config.addCollection("writingbyyear", (collection) => {
return lodash
.chain(collection.getFilteredByGlob(CONTENT_GLOBS.writing))
.filter((item) => !(item.data.draft && IS_PRODUCTION))
.groupBy((works) => works.date.getFullYear())
.toPairs()
.reverse()
.value()
})
// Base Config
return {
dir: {
input: "src",
output: "dist",
includes: "includes",
layouts: "layouts",
data: "data"
},
templateFormats: ["njk", "md", "11ty.js"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk"
}
}