-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
271 lines (215 loc) · 7.79 KB
/
eleventy.config.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//
//
//
//
const directoryOutputPlugin = require('@11ty/eleventy-plugin-directory-output');
const pluginRss = require('@11ty/eleventy-plugin-rss');
const sitemap = require('@quasibit/eleventy-plugin-sitemap');
//
const jsonData = require('./source/_data/site.json');
const shortcodes = require('./source/_config/eleventy.shortcodes.js');
const filters = require('./source/_config/eleventy.filters.js');
//
const markdownIt = require('markdown-it');
const markdownItDeflist = require('markdown-it-deflist');
const markdownItAnchor = require('markdown-it-anchor');
const markdownItTableOfContents = require('markdown-it-table-of-contents');
const markdownItFootnote = require('markdown-it-footnote');
//
const fs = require('fs');
const htmlmin = require('html-minifier');
//
const { DateTime } = require('luxon');
//
const isProduction = process.env.NODE_ENV === 'product';
//
//
//
module.exports = function (eleventyConfig) {
//
// eleventy-plugin-directory-output
//
eleventyConfig.addPlugin(directoryOutputPlugin, {
columns: {
filesize: true,
benchmark: true,
},
warningFileSize: 400 * 1000,
});
//
// 11ty Quiet Mode
//
eleventyConfig.setQuietMode(true);
//
// eleventy-plugin-rss
//
eleventyConfig.addPlugin(pluginRss, {
posthtmlRenderOptions: {
// See
// https://github.com/posthtml/posthtml-render#options
// https://learneleventyfromscratch.com/lesson/17.html#adding-an-rss-feed
closingSingleTag: 'default'
}
});
//
// eleventy-plugin-sitemap
//
eleventyConfig.addPlugin(sitemap, {
sitemap: {
hostname: jsonData.url,
},
});
//
// 11ty's addFilter
//
eleventyConfig.addFilter('setHeadTitle', filters.setHeadTitle);
eleventyConfig.addFilter('getCollectionsWelcomeMainContents', filters.getCollectionsWelcomeMainContents);
eleventyConfig.addFilter('getCollectionsWelcomeRecentUpdated', filters.getCollectionsWelcomeRecentUpdated);
eleventyConfig.addFilter('getCollectionsRelatedArticles', filters.getCollectionsRelatedArticles);
eleventyConfig.addFilter('getCollectionsFooter', filters.getCollectionsFooter);
eleventyConfig.addFilter('getBreadcrumb', filters.getBreadcrumb);
eleventyConfig.addFilter('setMyCustomOrder', filters.setMyCustomOrder);
//
// 11ty's addFilter with luxon
//
eleventyConfig.addFilter('readableDate', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' })
.toFormat('dd LLLL yyyy');
});
//
//
//
var collectionArray = [
{ collectionArray_name: 'contentsSectionsWelcome', collectionArray_path: './source/sections/welcome-*.md' },
{ collectionArray_name: 'contentsSectionsWhoAmI', collectionArray_path: './source/sections/who_am_i-*.md' },
];
collectionArray.forEach(function (element) {
eleventyConfig.addCollection(element.collectionArray_name, function (collectionApi) {
return collectionApi
.getFilteredByGlob(element.collectionArray_path)
.sort((a, b) => Number(a.data.order) > Number(b.data.order) ? 1 : -1);
});
});
//
// If 'updated' in *.md exists, sort it in descending order.
// If you use 'date', 11ty will see the date of the file's date.
// I wanted to avoid it. Therefore, I explicitly use 'updated'.
//
eleventyConfig.addCollection('myCustomSortRecentUpdated', function (collectionApi) {
return collectionApi
.getAll()
.filter(function (value) {
if (null != value.data.updated) {
return value;
}
})
.sort(function (a, b) {
return b.data.updated - a.data.updated;
});
});
//
// 11ty's addShortcode
//
eleventyConfig.addShortcode('youtubeEmbed', shortcodes.youtubeEmbed);
eleventyConfig.addShortcode('nicovideoEmbed', shortcodes.nicovideoEmbed);
eleventyConfig.addShortcode('imageEmbed', shortcodes.imageEmbed);
eleventyConfig.addShortcode('rubyEmbed', shortcodes.rubyEmbed);
//
// 11ty's setNunjucksEnvironmentOptions
//
eleventyConfig.setNunjucksEnvironmentOptions({
throwOnUndefined: true,
autoescape: false, // warning: don’t do this!
});
//
// Various markdown settings
//
let markdownIt_options = {
html: true,
breaks: true,
linkify: true,
};
let markdownItTableOfContents_options = {
includeLevel: [3, 4, 5],
containerClass: 'table-of-contents',
markerPattern: /^\[\[toc\]\]/im,
listType: 'ol',
containerHeaderHtml: '<h2>Table of contents...</h2>',
containerFooterHtml: '',
};
let markdownItFootnote_options = {
html: true,
linkify: true,
typographer: true
};
let markdownLib = markdownIt(markdownIt_options)
.use(markdownItDeflist)
.use(markdownItTableOfContents, markdownItTableOfContents_options)
.use(markdownItAnchor)
.use(markdownItFootnote, markdownItFootnote_options);
markdownLib.renderer.rules.footnote_block_open = () =>
'<section class="footnotes">' + '<hr>' + '<h2>Footnotes...</h2>' + '<ol>';
eleventyConfig.setLibrary('md', markdownLib);
//
// 11ty's addPassthroughCopy
//
eleventyConfig.addPassthroughCopy({ './source/static/assets/webfonts': './assets/webfonts' });
eleventyConfig.addPassthroughCopy({ './source/static/assets/styles/images': './assets/styles/images' });
eleventyConfig.addPassthroughCopy({ './source/static/assets/styles/fontawesome-all.min.css': './assets/styles/fontawesome-all.min.css' });
eleventyConfig.addPassthroughCopy({ './source/static/assets/scripts/breakpoints.min.js': './assets/scripts/breakpoints.min.js' });
eleventyConfig.addPassthroughCopy({ './source/static/assets/scripts/browser.min.js': './assets/scripts/browser.min.js' });
eleventyConfig.addPassthroughCopy({ './source/static/assets/scripts/jquery.min.js': './assets/scripts/jquery.min.js' });
eleventyConfig.addPassthroughCopy({ './source/static/assets/scripts/jquery.scrollex.min.js': './assets/scripts/jquery.scrollex.min.js' });
eleventyConfig.addPassthroughCopy({ './source/static/meta/**': './' });
//
// 11ty's addWatchTarget and setWatchThrottleWaitTime
//
eleventyConfig.addWatchTarget('./source/assets/styles/**/*');
eleventyConfig.setWatchThrottleWaitTime(999);
//
if (isProduction) {
//
// html-minifier
//
eleventyConfig.addTransform('htmlmin', function(content) {
if (this.page.outputPath && this.page.outputPath.endsWith('.html')) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
});
return minified;
}
return content;
});
} else {
//
// eleventy-dev-server, included with 11ty's installation
//
eleventyConfig.setServerOptions({
liveReload: true,
domDiff: true,
port: 8080,
watch: [],
showAllHosts: false,
https: {},
encoding: 'utf-8',
showVersion: false,
});
}
//
//
//
return {
markdownTemplateEngine: 'njk',
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
dir: {
input: './source',
layouts: './_includes/layouts',
output: isProduction ? './_product' : './_develop'
}
};
};