-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
88 lines (70 loc) · 2.21 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
const syntaxHighlightPlugin = require("@11ty/eleventy-plugin-syntaxhighlight");
const rssPlugin = require("@11ty/eleventy-plugin-rss");
const CleanCSS = require("clean-css");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlightPlugin);
eleventyConfig.addPlugin(rssPlugin);
eleventyConfig.addPassthroughCopy("css/fonts");
eleventyConfig.addPassthroughCopy("img");
eleventyConfig.addFilter("cssmin", function(code) {
return new CleanCSS({}).minify(code).styles;
});
eleventyConfig.addFilter("sortMenu", function(collection, sortOrder) {
if(!sortOrder) {
return collection;
}
let order = sortOrder.map(path => `./docs/${path}.md`);
return collection.sort(function(a, b) {
let firstIndex = order.indexOf(a.inputPath);
let secondIndex = order.indexOf(b.inputPath);
if( firstIndex === -1 ) return 1;
if( secondIndex === -1 ) return -1;
return firstIndex - secondIndex;
});
});
eleventyConfig.addFilter("latestVersion", function(versions) {
for( let version of versions ) {
if( version.tag === "LATEST" ) {
continue;
}
return version.tag;
}
});
eleventyConfig.addFilter("orphanWrap", str => {
let splitSpace = str.split(" ");
let after = "";
if( splitSpace.length > 2 ) {
after += " ";
// TODO strip HTML from this?
let lastWord = splitSpace.pop();
let secondLastWord = splitSpace.pop();
after += `<span class="prevent-orphan">${secondLastWord} ${lastWord}</span>`;
}
return splitSpace.join(" ") + after;
});
eleventyConfig.addCollection("quicktipssorted", function(collection) {
return collection.getFilteredByTag("quicktips").sort(function(a, b) {
return parseInt(a.data.tipindex, 10) - parseInt(b.data.tipindex, 10);
});
});
/* Markdown */
let markdownIt = require("markdown-it");
let markdownItAnchor = require("markdown-it-anchor");
let options = {
html: true,
breaks: true,
linkify: true
};
let opts = {
permalink: true,
permalinkClass: "direct-link",
permalinkSymbol: "#",
level: [1,2,3,4]
};
eleventyConfig.setLibrary("md", markdownIt(options).use(markdownItAnchor, opts));
return {
templateFormats: ["html", "njk", "md"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk"
};
};