-
Notifications
You must be signed in to change notification settings - Fork 72
/
eleventy.config.js
101 lines (87 loc) · 2.56 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
/** @format */
const htmlmin = require('html-minifier');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const i18n = require('eleventy-plugin-i18n');
const translations = require('./src/_data/i18n');
module.exports = (eleventyConfig) => {
// i18n translations
eleventyConfig.addPlugin(i18n, {
translations,
fallbackLocales: {
'*': 'en',
},
});
// Minify our HTML
eleventyConfig.addTransform('htmlmin', (content, outputPath) => {
if (outputPath.endsWith('.html')) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});
// Layout aliases
eleventyConfig.addLayoutAlias('default', 'default.njk');
eleventyConfig.addLayoutAlias('home', 'home.njk');
// Include our static assets
eleventyConfig.addPassthroughCopy('images');
eleventyConfig.addPassthroughCopy('demos');
eleventyConfig.addPlugin(syntaxHighlight, {
alwaysWrapLineHighlights: false,
});
let md = require('markdown-it')({
html: true,
breaks: true,
linkify: true,
});
md.use(require('markdown-it-attrs'));
md.use(require('markdown-it-anchor'));
eleventyConfig.setLibrary('md', md);
// Cut back on terminal noise during development
eleventyConfig.setQuietMode(true);
// Collection of pages that can appear in search results
eleventyConfig.addCollection('searchPages', (collection) => {
return collection
.getFilteredByGlob('src/*.md')
.sort((a, b) => {
if (a.data.title < b.data.title) return -1;
if (a.data.title > b.date.title) return 1;
return 0;
})
.filter((page) => {
return !page.data.hidden;
});
});
// Helper for extracting the searchable content in a page
eleventyConfig.addShortcode('searchContent', (page) => {
if (!page.hasOwnProperty('templateContent')) {
console.warn(
'Failed to extract excerpt: Document has no property "templateContent".'
);
return null;
}
return JSON.stringify(page.templateContent)
.slice(1, -1)
.replace(/[\n]\s*[\n]/gm, '\n')
.replace(/<h1[^>]*.*<\/h1>/gm, '')
.replace(/<[^>]*>/g, '')
.replace(/^\\n/g, '')
.trim();
});
return {
templateFormats: ['md', 'njk'],
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
passthroughFileCopy: true,
dir: {
input: 'src',
output: 'dist',
layouts: '_layouts',
includes: '_includes',
data: '_data',
},
};
};