-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
89 lines (73 loc) · 2.8 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
const markdownIt = require("markdown-it");
const markdownItAttrs = require('markdown-it-attrs')
const markdownItFootnote = require("markdown-it-footnote");
const { DateTime } = require("luxon");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
module.exports = (function(eleventyConfig) {
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(syntaxHighlight);
// Copy /images to /public
eleventyConfig.addPassthroughCopy('images');
eleventyConfig.addPassthroughCopy({'source/fonts/': 'fonts/'});
eleventyConfig.addPassthroughCopy({'source/js/': 'js/'});
eleventyConfig.addPassthroughCopy({'source/theme/': 'theme/'});
// filter to parse markdown
const md = new markdownIt({
html: true,
});
eleventyConfig.addFilter("markdown", (content) => {
return md.render(content);
});
// enable classes and attributes in markdown
const markdownItOptions = {
html: true,
linkify: true
}
const markdownLib = markdownIt(markdownItOptions)
.use(markdownItAttrs)
.use(markdownItFootnote);
markdownLib.renderer.rules.footnote_caption = (tokens, idx) => {
let n = Number(tokens[idx].meta.id + 1).toString();
if (tokens[idx].meta.subId > 0) {
n += ":" + tokens[idx].meta.subId;
}
return n;
};
eleventyConfig.setLibrary('md', markdownLib)
// Debug filter
eleventyConfig.addFilter("log", (d) => {
console.log(d);
});
// typeof for array, using native JS Array.isArray()
eleventyConfig.addFilter('isArray', something => Array.isArray(something))
// Filter to display dates
eleventyConfig.addFilter("postDate", (dateObj) => {
// see Luxon ref to change format https://moment.github.io/luxon/#/formatting
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_MED);
});
eleventyConfig.addFilter("topTags", (d) => {
let tags = [];
for (const [key, value] of Object.entries(d)) {
tags.push({name: key, count: value.length});
};
tags.sort((a, b) => parseFloat(b.count) - parseFloat(a.count));
tags.shift(); // remove first item "all"
tags = tags.slice(0, 10); // take top 10
return tags;
});
eleventyConfig.addCollection("allTags", function(collectionApi) {
const tagsList = new Set();
collectionApi.getAll().map( item => {
if (item.data.tags) { // handle pages that don't have tags
item.data.tags.map( tag => tagsList.add(tag))
}
});
return tagsList;
});
// set nunjucks as markdown template engine
// could be useful for custom processing like mermaid
// return {
// markdownTemplateEngine: "njk, md"
// }
});