-
Notifications
You must be signed in to change notification settings - Fork 67
/
.eleventy.js
118 lines (100 loc) · 3.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
const authors = require('./hell/_data/authors.js')
const pluginRss = require("@11ty/eleventy-plugin-rss");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const filters = require('./_11ty/filters.js')
const pluginPWA = require('eleventy-plugin-pwa');
const htmlmin = require('html-minifier');
const markdownIt = require('markdown-it');
const markdownItAnchor = require("markdown-it-anchor");
const slugify = require("slugify");
module.exports = function (eleventyConfig) {
// Filters
Object.keys(filters).forEach(filterName => {
eleventyConfig.addFilter(filterName, filters[filterName])
});
// Shortcodes
eleventyConfig.addNunjucksShortcode("author", function (id) {
let authorHTML;
authors.authors.filter(author => {
if (author.id === id) {
authorHTML = `<a href="${author.link}" rel="noopener">${author.name}</a>`;
}
});
return authorHTML;
});
// Transforms
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
if (outputPath.endsWith('.html')) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});
// Collections
eleventyConfig.addCollection("entries", function (collection) {
return collection.getFilteredByGlob("./hell/entries/*.md");
});
function markdownItSlugify(s) {
return slugify(s, { lower: true, remove: /[:’'.`,]/g });
}
let mdIt = markdownIt({
html: true,
breaks: true,
linkify: true
})
.use(markdownItAnchor, {
permalink: true,
slugify: markdownItSlugify,
permalinkBefore: false,
permalinkSymbol: "#",
renderPermalink: (slug, opts, state, idx) => {
// const headingText = state.tokens[idx + 1].children[0].content;
// const headingHTML= `<span class="u-hidden">${headingText}</span>`;
// const space = () => Object.assign(new state.Token('text', '', 0), { content: ' ' })
// const linkTokens = [
// Object.assign(new state.Token('link_open', 'a', 1), {
// attrs: [
// ['href', opts.permalinkHref(slug, state)],
// ...Object.entries(opts.permalinkAttrs(slug, state))
// ]
// }),
// Object.assign(new state.Token('html_block', '', 0), { content: `<span aria-hidden="true">${opts.permalinkSymbol}</span>` + headingHTML }),
// new state.Token('link_close', 'a', -1)
// ]
// linkTokens.push(space())
// state.tokens[idx + 1].children.unshift(...linkTokens)
},
level: [2, 3]
});
eleventyConfig.setLibrary("md", mdIt);
// Plugins
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPassthroughCopy({ "./hell/assets": "assets" });
eleventyConfig.addPassthroughCopy({ "./hell/favicon/*": "/" });
eleventyConfig.addPassthroughCopy("./hell/images");
eleventyConfig.addPassthroughCopy("./hell/robots.txt");
eleventyConfig.addPassthroughCopy("./hell/adventcalendar/**/*.!(md)");
eleventyConfig.addPlugin(pluginPWA);
return {
templateFormats: [
"md",
"njk"
],
pathPrefix: "/",
markdownTemplateEngine: "liquid",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
passthroughFileCopy: true,
dir: {
input: "hell",
includes: "_includes",
data: "_data",
output: "_site"
}
};
};