-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
192 lines (169 loc) · 5.85 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
const glob = require("glob")
const inclusiveLangPlugin = require("@11ty/eleventy-plugin-inclusive-language")
const lazyImagesPlugin = require("eleventy-plugin-lazyimages")
const pluginRss = require("@11ty/eleventy-plugin-rss")
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight")
const markdownIt = require("markdown-it")
const markdownItFootnote = require("markdown-it-footnote")
const markdownItAnchor = require("markdown-it-anchor")
const markdownItToc = require("markdown-it-table-of-contents")
const markdownItFigures = require("markdown-it-implicit-figures")
const markdownItKlipse = require("./src/_plugins/markdown-it-klipse")
const markdownItTitle = require("./src/_plugins/markdown-it-title")
const markdownItMermaid = require("./src/_plugins/markdown-it-mermaid")
const markdownItDefaultType = require("./src/_plugins/markdown-it-default-type")
const markdownItArrow = require("./src/_plugins/markdown-it-arrow")
const svgContents = require("eleventy-plugin-svg-contents")
module.exports = function (eleventyConfig) {
// Ignore files and folders
eleventyConfig.ignores.add("_drafts/")
// Copy files
eleventyConfig.addPassthroughCopy("_redirects")
eleventyConfig.addPassthroughCopy("src/{blog,notes,talks,labs}/**/*")
eleventyConfig.addPassthroughCopy("src/css/*.css")
eleventyConfig.addPassthroughCopy("src/fonts/*.woff2")
eleventyConfig.addPassthroughCopy("src/js/*.js")
eleventyConfig.addPassthroughCopy("src/favicon.ico")
eleventyConfig.addPassthroughCopy("src/robots.txt")
eleventyConfig.addPassthroughCopy("src/shortcuts/*")
eleventyConfig.addPassthroughCopy("src/images/*")
// All attachment images will be in one folder '/' because it is easier
// to manage correct references to them (only the name)
eleventyConfig.addPassthroughCopy({
"src/**/*.{ico,png,svg,gif,jpg,jpeg}": "/",
})
// Create collections
eleventyConfig.addCollection("blog", collectionByFolders("blog/"))
eleventyConfig.addCollection("notes", collectionByFolders("notes/"))
eleventyConfig.addCollection(
"labs",
collectionByFolderAndFile("labs/", "README"),
)
eleventyConfig.addCollection(
"talks",
collectionByFolderAndFile("talks/", "README"),
)
eleventyConfig.addCollection("feed", collectionByFolders("blog/"))
eleventyConfig.addCollection(
"posts",
collectionByFolders("blog/", "labs/", "notes/"),
)
eleventyConfig.addCollection("tagList", getTagList)
// Configure front matter
eleventyConfig.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "---",
})
// Configure markdown
const markdownOptions = {
html: true,
breaks: false,
linkify: true,
typographer: true,
}
const md = markdownIt(markdownOptions)
.use(markdownItFootnote)
.use(markdownItAnchor, {
level: [2, 3],
permalink: markdownItAnchor.permalink.headerLink(),
})
.use(markdownItToc, {
includeLevel: [2],
containerHeaderHtml: '<div class="toc-heading">Table of content</div>',
markerPattern: /^\[-\[TOC\]-\]/im,
})
.use(markdownItFigures, {
figcaption: true,
})
// my custom plugins
.use(markdownItKlipse)
.use(markdownItTitle)
.use(markdownItMermaid)
.use(markdownItDefaultType)
.use(markdownItArrow)
md.renderer.rules.footnote_block_open = () =>
`<h4 class="footnotes-title">Notes</h4>
<section class="footnotes">
<ol class="footnotes-list">`
eleventyConfig.setLibrary("md", md)
// Configure watch mode
eleventyConfig.addWatchTarget("**/*.md")
eleventyConfig.addWatchTarget("./src/**/*.js")
eleventyConfig.addWatchTarget("./src/**/*.css")
// Add plugins
eleventyConfig.addPlugin(lazyImagesPlugin, {
cacheFile: ".datacache/lazyimages",
imgSelector: ".post-content img",
transformImgPath: (relativePath) => {
// For image paths find the full path relative to project root
// otherwise lazyImagesPlugin would not be able to locate the image.
if (relativePath.startsWith("/") || relativePath.startsWith("./")) {
relativePath = relativePath.replace(/^.*\/(.*)/, "$1")
}
const files = glob.sync("src/**/" + relativePath)
if (Array.isArray(files) && files[0]) {
relativePath = files[0]
if (files.length > 1) {
console.warn("More than one file with the same name was found!")
}
}
return relativePath
},
})
eleventyConfig.addPlugin(inclusiveLangPlugin, {
words: "simply,obviously,basically,of course,clearly,just,everyone knows",
})
eleventyConfig.addPlugin(pluginRss)
eleventyConfig.addPlugin(syntaxHighlight, {
alwaysWrapLineHighlights: true,
})
eleventyConfig.addPlugin(svgContents)
// Prism.js does not know mermaid, it has to be processed manually here
const highlighter = eleventyConfig.markdownHighlighter
eleventyConfig.addMarkdownHighlighter((str, language) => {
if (language === "mermaid") {
return `<pre class="mermaid">${str}</pre>`
}
return highlighter(str, language)
})
return {
// Configure used template formats
templateFormats: ["11ty.js", "md", "njk"],
dir: {
input: "src",
output: "dist",
},
}
}
function collectionByFolders(...folderNames) {
return function (collection) {
return collection
.getAllSorted()
.filter((item) =>
folderNames.some((folderName) => item.inputPath.includes(folderName)),
)
.reverse()
}
}
function collectionByFolderAndFile(folderName, fileName) {
return function (collection) {
return collection
.getAllSorted()
.filter(
(item) =>
item.inputPath.includes(folderName) &&
item.inputPath.includes(fileName),
)
.reverse()
}
}
function getTagList(collection) {
return [
...new Set(
collection
.getAll()
.filter((item) => Array.isArray(item.data.tags))
.flatMap((item) => item.data.tags),
),
]
}