-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
189 lines (168 loc) · 6.01 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
const emojiRegex = require("emoji-regex");
const slugify = require("slugify");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginTOC = require('eleventy-plugin-toc');
const pluginDropcap = require('eleventy-plugin-dropcap');
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItHighlightJS = require('markdown-it-highlightjs')
const packageVersion = require("./package.json").version;
const fs = require("fs");
const inclusiveLangPlugin = require("@11ty/eleventy-plugin-inclusive-language");
const mdOptions = {
html: true,
breaks: true,
linkify: true,
typographer: true
}
const mdAnchorOpts = {
permalink: markdownItAnchor.permalink.linkInsideHeader({
symbol: '#',
class: 'anchor-link',
}),
level: [2, 3, 4]
}
// const formatDate = date => DateTime.fromJSDate(new Date(date)).toISO({includeOffset: true, suppressMilliseconds: true})
// const formatDateYear = date => DateTime.fromJSDate(new Date(date)).get('year')
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(pluginRss, {
posthtmlRenderOptions: {
closingSingleTag: "default" // opt-out of <img/>-style XHTML single tags
}
});
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(inclusiveLangPlugin, {
templateFormats: ["md, html"], // default, add more file extensions here
// accepts an array or a comma-delimited string
words:
"simply,obviously,basically,of course,clearly,just,everyone knows,however,easy",
});
eleventyConfig.addWatchTarget("src/sass/*.scss");
eleventyConfig.addPassthroughCopy("src/img");
eleventyConfig.addPassthroughCopy("src/webfonts");
eleventyConfig.addPassthroughCopy("src/cache-polyfill.js");
eleventyConfig.addPassthroughCopy("src/CNAME");
eleventyConfig.addPassthroughCopy("src/favicon.*");
eleventyConfig.addPassthroughCopy("src/favicon-16x16.png");
eleventyConfig.addPassthroughCopy("src/favicon-32x32.png");
eleventyConfig.addPassthroughCopy("src/apple-touch-icon.png");
eleventyConfig.addPassthroughCopy("src/safari-pinned-tab.svg");
eleventyConfig.addPassthroughCopy("src/android-chrome-192x192.png");
eleventyConfig.addPassthroughCopy("src/android-chrome-512x512.png");
eleventyConfig.addPassthroughCopy("src/faviconData.json");
eleventyConfig.addPassthroughCopy("src/keybase.txt");
eleventyConfig.addPassthroughCopy("src/manifest.json");
eleventyConfig.addPassthroughCopy("src/sw.js");
eleventyConfig.addPassthroughCopy("src/js/**");
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
eleventyConfig.addShortcode("packageVersion", () => `v${packageVersion}`);
/* Use for v3 upgrade in order to bypass the reservation of Collections name */
eleventyConfig.setFreezeReservedData(false);
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: function(err, bs) {
bs.addMiddleware("*", (req, res) => {
const content_404 = fs.readFileSync('./docs/404.html');
// Add 404 http status code in request header.
res.writeHead(404, { "Content-Type": "text/html; charset=UTF-8" });
// Provides the 404 content without redirect.
res.write(content_404);
res.end();
});
}
}
});
eleventyConfig.addFilter("slug", (str) => {
if (!str) {
return;
}
const regex = emojiRegex();
// Remove Emoji first
let string = str.replace(regex, "");
return slugify(string, {
lower: true,
replacement: "-",
remove: /[*+~·,()'"`´%!?¿:@\/]/g,
});
});
// Markdown
eleventyConfig.setLibrary(
'md',
markdownIt(mdOptions)
.use(markdownItAnchor, mdAnchorOpts)
.use(markdownItHighlightJS)
);
// Plugins
// https://github.com/jdsteinbach/jdsteinbach.github.io/blob/blog/.eleventy.js
// https://github.com/jdsteinbach/eleventy-plugin-toc
eleventyConfig.addPlugin(pluginTOC, {
tags: ["h2", "h3", "h4"],
wrapper: "div",
wrapperClass: "toc markdown-toc",
ul: true,
flat: false
});
eleventyConfig.addPlugin(
pluginDropcap,
{skipFirstParagraphClass: 'precursor'}
);
// Create Posts Collection
// https://github.com/jdsteinbach/jdsteinbach.github.io/blob/blog/.eleventy.js
eleventyConfig.addCollection('posts', collection => {
return collection
.getAllSorted()
.reverse()
.filter(item => {
return item.inputPath.match(/^\.\/src\/posts\//) !== null
})
});
// Create Posts Index Collection
// https://github.com/jdsteinbach/jdsteinbach.github.io/blob/blog/.eleventy.js
eleventyConfig.addCollection('postsIndex', collection => {
return collection
.getAllSorted()
.reverse()
.filter(item => {
return item.inputPath.match(/^\.\/src\/posts\//) !== null
})
.slice(0, 8)
});
// Create Posts Feed Collection
// https://github.com/jdsteinbach/jdsteinbach.github.io/blob/blog/.eleventy.js
eleventyConfig.addCollection('postsFeed', collection => {
return collection
.getAllSorted()
.reverse()
.filter(item => {
return item.inputPath.match(/^\.\/src\/posts\//) !== null
})
.slice(0, 10)
});
// Create Category Collections
// https://github.com/jdsteinbach/jdsteinbach.github.io/blob/blog/.eleventy.js
Array.from(['development', 'general', 'design', 'portfolio']).map(cat => {
eleventyConfig.addCollection(cat, collection => {
return collection
.getAllSorted()
.filter(item => {
if ('categories' in item.data) {
return item.data.categories.filter(category => {
return category.toLowerCase() === cat.toLowerCase()
}).length > 0
}
return false
})
.reverse()
})
});
return {
passthroughFileCopy: true,
dir: {
input: "src",
output: "docs",
},
};
};