-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
201 lines (179 loc) · 6.41 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
193
194
195
196
197
198
199
200
201
const { DateTime } = require("luxon");
const fs = require("fs");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const slugify = require("slugify");
const splitTitle = require("./_11ty/splitTitle.js");
const striptags = require("striptags");
const EleventyPluginOgImage = require('eleventy-plugin-og-image');
const Image = require("@11ty/eleventy-img");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.setDataDeepMerge(true);
const OgImageOptions = {
generateHTML: (outputUrl) => outputUrl,
satoriOptions: {
fonts: [
{
name: 'EB Garamond',
data: fs.readFileSync('assets/fonts/static/EBGaramond-Regular.ttf'),
style: 'normal',
weight: 400
},
{
name: 'EB Garamond',
data: fs.readFileSync('assets/fonts/static/EBGaramond-Italic.ttf'),
style: 'italic',
weight: 400
}
],
},
}
eleventyConfig.addPlugin(EleventyPluginOgImage, OgImageOptions);
eleventyConfig.addLayoutAlias("base", "layouts/base.njk");
eleventyConfig.addLayoutAlias("article", "layouts/article.njk");
eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("LLLL dd, yyyy");
});
eleventyConfig.addFilter("year", dateObj => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("yyyy");
});
eleventyConfig.addFilter("slugify-removeChars", function(value) {
let product = slugify(value, {
replacement: '-', // replace spaces with replacement
remove: /[*+~.()'"!:@’“”]/g, // regex to remove characters
lower: true // result in lower case
})
return product;
});
eleventyConfig.addFilter("striptags", function(value) {
return striptags(value);
});
eleventyConfig.addFilter("shortTitle", function(value) {
return splitTitle.shortTitle(value);
});
eleventyConfig.addFilter("subtitle", function(value) {
return splitTitle.subtitle(value);
});
eleventyConfig.addFilter("filterByAuthor", function(collection, author) {
let product = collection.filter((article) => article.data.author === author )
return product
});
eleventyConfig.addFilter("sortAuthorsByArticleNumber", function(collection) {
let product = collection.sort((a, b) => {
return Number(a.data.articlenumber) - Number(b.data.articlenumber)
})
return product
});
// shortcodes
eleventyConfig.addShortcode("ytEmbed", require("./_11ty/ytEmbed.js"));
eleventyConfig.addShortcode("citation", require("./_11ty/citation.js"));
// https://github.com/KiwiKilian/eleventy-plugin-og-image/issues/36
// I just ended up using a remote image, so this is not necessary (it didn't
// work either). A better solution might be able to be found.
// eleventyConfig.addShortcode("inlineImage", (path) => {
// const file = fs.readFileSync(path);
// return `data:image/jpeg;base64,${file.toString('base64')}`;
// });
eleventyConfig.addShortcode("image", require("./_11ty/image.js"));
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd');
});
// Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => {
if( n < 0 ) {
return array.slice(n);
}
return array.slice(0, n);
});
eleventyConfig.addCollection("tagList", require("./_11ty/getTagList"));
// passthrough
eleventyConfig.addPassthroughCopy("assets/js");
eleventyConfig.addPassthroughCopy("assets/css");
eleventyConfig.addPassthroughCopy("assets/files");
eleventyConfig.addPassthroughCopy("assets/fonts");
eleventyConfig.addPassthroughCopy("assets/images");
eleventyConfig.addPassthroughCopy("robots.txt");
eleventyConfig.addPassthroughCopy("CNAME");
eleventyConfig.addPassthroughCopy("favicon.ico");
/* Markdown Plugins */
let markdownIt = require("markdown-it");
let markdownItAnchor = require("markdown-it-anchor");
let markdownItDeflist = require("markdown-it-deflist");
let markdownItFootnote = require('markdown-it-footnote');
let markdownItAttrs = require("markdown-it-attrs");
let markdownItResponsive = require("./_11ty/markdownItResponsive.js");
let mdOptions = {
html: true,
breaks: false,
linkify: true,
typographer: true
};
let anchorOptions = {
permalink: false,
permalinkClass: "direct-link",
permalinkSymbol: "#"
};
let riOptions = {
widths: [150, 300, 600, 800, 1000, 2000],
sizes: "(max-width: 60rem) 100vw, 66vw"
};
let md = markdownIt(mdOptions)
.use(markdownItAnchor, anchorOptions)
.use(markdownItDeflist)
.use(markdownItAttrs)
.use(markdownItFootnote)
.use(markdownItResponsive, riOptions);
eleventyConfig.setLibrary("md", md);
md.renderer.rules.footnote_block_open = function () {
return '<h2>Footnotes</h2> \n <ol>';
};
md.renderer.rules.footnote_block_close = function () {
return '</ol>';
};
md.renderer.rules.footnote_anchor = function () {
return "";
};
md.renderer.rules.footnote_caption = function (tokens, idx) {
var n = Number(tokens[idx].meta.id + 1).toString();
if (tokens[idx].meta.subId > 0) {
n += ':' + tokens[idx].meta.subId;
}
return n;
};
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: function(err, browserSync) {
const content_404 = fs.readFileSync('_site/404.html');
browserSync.addMiddleware("*", (req, res) => {
// Provides the 404 content without redirect.
res.write(content_404);
res.end();
});
}
}
});
return {
templateFormats: [
"md",
"njk",
"html",
"liquid"
],
// If your site lives in a different subdirectory, change this.
// Leading or trailing slashes are all normalized away, so don’t worry about it.
// If you don’t have a subdirectory, use "" or "/" (they do the same thing)
// This is only used for URLs (it does not affect your file structure)
pathPrefix: "/",
markdownTemplateEngine: "liquid",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
passthroughFileCopy: true,
dir: {
input: ".",
includes: "_includes",
data: "_data",
output: "_site"
}
}
};