-
Notifications
You must be signed in to change notification settings - Fork 26
/
.eleventy.js
165 lines (130 loc) · 5.19 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
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const markdownIt = require("markdown-it");
const pluginTOC = require('eleventy-plugin-toc');
module.exports = function (config) {
// ----------------------- Plugins -----------------------
config.addPlugin(syntaxHighlight);
config.addPlugin(pluginTOC, {
wrapper: "div",
ul: true,
wrapperClass: "toc-list",
});
// ----------------------- Layouts -----------------------
[
"default", "narrow", "post", "video", "page", "course", "newsletter",
].forEach((layoutName) => {
config.addLayoutAlias(layoutName, `layouts/${layoutName}.html`);
});
// ----------------------- Custom filters -----------------------
[
"getVideosInSeries", "getFeatureable", "indexOf", "getRelated",
"htmlImageSize", "groupByYear", "startsWith", "filterArrayStartsWith",
"getThumbnailUrl", "getTitle"
].forEach((filterName) => {
config.addLiquidFilter(filterName,
require('./src/utils/filters/' + filterName));
});
// ----------------------- Collections -----------------------
config.addCollection('courses', (collectionApi) => {
return collectionApi.getFilteredByGlob('src/site/courses/**/index.md');
});
config.addCollection('newsletter', (collectionApi) => {
return collectionApi.getFilteredByGlob('src/site/newsletter/**/*.md');
});
config.addCollection('posts', (collectionApi) => {
return collectionApi.getFilteredByGlob('src/site/posts/**/*.md')
.sort(function (a, b) {
return b.date - a.date;
});
});
config.addCollection('videos', (collectionApi) => {
return collectionApi.getFilteredByGlob('src/site/videos/**/*.md')
.sort((a, b) => {
return b.date - a.date;
});
});
config.addCollection("tags", function (collection) {
const tags = new Set();
for (const item of collection.getAll()) {
if ("tags" in item.data) {
for (const tag of item.data.tags) {
tags.add(tag);
}
}
}
return [...tags].sort();
});
config.addCollection('trivia', (collectionApi) => {
return collectionApi.getFilteredByGlob('src/site/trivia/**/*.md')
.sort(function (a, b) {
return b.date - a.date;
});
});
// ----------------------- Custom shortcodes -----------------------
config.addShortcode("link", require('./src/utils/shortcode/link.js'));
config.addPairedShortcode("bibtex", require('eleventy-plugin-bibtex'));
config.addPairedShortcode("xd_img", require('./src/utils/shortcode/xd_img'));
config.addShortcode("baseUrl", () => "https://simplyexplained.com");
// ----------------------- File copies -----------------------
[
"src/site/assets",
"src/site/robots.txt",
// Ignore all files starting with underscore (private files such as
// thumbnail designs)
"src/site/uploads/**/(?!_)*",
// Copy all resource files (except the markdown files themselves)
"src/site/courses/**/*[^md]",
"src/site/projects/**/*[^md]",
"src/site/videos/**/*[^md]",
"src/site/newsletter/assets/**/*[^md]",
"src/site/trivia/**/*[^md]",
].forEach(path => config.addPassthroughCopy(path));
// Extract excerpt for each post containing the <!--more--> tag
// Used to construct SEO <meta> tags in <head>
config.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "<!--more-->"
});
// Markdown option: external links should be opened in a
// new tab and not expose personal details
const milaOptions = {
matcher(href) {
return href.match(/^https?:\/\//);
},
attrs: {
target: "_blank",
rel: "noopener noreferrer"
}
};
// Main options for the Markdown renderer
const markdownOptions = {
// Allow HTML tags inside md files
html: true,
};
const markdownLib = markdownIt(markdownOptions)
// Makes sure that each external link opens in a new tab
.use(require("markdown-it-link-attributes"), milaOptions)
// Generates anchors for all headings (used for table of contents)
.use(require('markdown-it-anchor'))
// Generate table of contents when asked (needs anchors to work)
// Needed for inline [[TOC]]
.use(require("markdown-it-table-of-contents"))
.use(require('markdown-it-footnote'))
// Lazy load all images by default (browser support needed)
.use(require('./src/utils/markdown-it-xd-images'), {
image_size: true,
base_path: __dirname + '/src/site',
});
config.setLibrary("md", markdownLib);
config.addLiquidFilter("md", (content = "") => {
return markdownLib.render(content);
});
config.setLiquidOptions({
strictFilters: true,
orderedFilterParameters: true,
lenientIf: true,
});
return {
dir: { input: 'src/site', output: '_site', data: '_data' },
};
};