-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
145 lines (114 loc) · 3.04 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
const { slugify } = require('./utils');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
module.exports = function (config) {
/* Plugin Markdown */
const md = require("markdown-it")({
breaks: true,
});
md.use( require('markdown-it-sub') );
md.use( require('markdown-it-sup') );
md.use( require('markdown-it-attrs') );
md.use( require('markdown-it-anchor'), {
slugify
});
md.use( require("markdown-it-toc-done-right"), {
level: [2, 3, 4, 5],
slugify,
});
md.use( require('markdown-it-container'), 'details', {
validate: function(params) {
return params.trim().match(/^details\s+\[(.*)\]$/);
},
render: function (tokens, idx) {
const m = tokens[idx].info.trim().match(/^details\s+\[(.*)\]$/);
if (tokens[idx].nesting === 1) {
// opening tag
return "<details>\n"
+ ' <summary>\n'
+ ` <span>${md.utils.escapeHtml(m[1])}</span>\n`
+ ' </summary>\n'
+ ' <div>\n';
} else {
// closing tag
return ' </div>\n</details>\n';
}
}
});
md.use( require('markdown-it-texmath'), {
engine: require('katex'),
katexOptions: {
displayMode: true,
output: 'mathml'
}
});
config.setLibrary("md", md);
/* Collections */
config.addCollection('pageTags', (collections) => {
const uniqueTags = [...new Set(collections
.getAll()
.reduce((tags, item) => tags.concat(item.data.tags), [])
.filter((tag) => !!tag)
.filter((tag) => !!tag && !['page', 'post'].includes(tag))
.sort())];
return uniqueTags;
});
/* Filters */
config.addFilter('capitalize', (str) => {
if (str)
return str.trim()
.replace(/^(.)(.*)$/, (all, first, others) => (
first.toUpperCase() + others.toLowerCase()
));
});
config.addFilter('lowercase', (str) => {
if (str)
return str.trim().toLowerCase();
});
/**
* Returns a subset of pages of the specified category
*/
config.addFilter('only', (pages, category) => {
if (pages)
return pages
.filter((p) => !p.data.hidden)
.filter((p) => (
p.data.category === category
));
});
/**
* Extract previous and next page of a collection of pages
*/
config.addFilter('getNextPrevOf', (pages, url) => {
if (!pages)
return;
let wasFound = false;
const idx = pages.reduce((counter, p) => {
if (wasFound)
return counter;
wasFound = p.url === url;
return !wasFound ? ++counter : counter
}, 0)
if (wasFound) {
return {
prev: pages[idx-1],
next: pages[idx+1],
}
}
})
config.addPlugin(syntaxHighlight, {
alwaysWrapLineHighlights: false
});
/* Passthrough copies */
config.addPassthroughCopy("styles");
config.addPassthroughCopy("assets");
config.addPassthroughCopy("src/**/*.md");
return {
dir: {
input: 'src',
output: 'build',
layouts: '_layouts',
includes: '_includes',
data: '_data'
}
};
};