-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eleventy.js
86 lines (72 loc) · 2.65 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
var env = process.env.ELEVENTY_ENV;
module.exports = function(eleventyConfig) {
// syntax highlighting plugin
const syntaxHighlightPlugin = require("@11ty/eleventy-plugin-syntaxhighlight");
eleventyConfig.addPlugin(syntaxHighlightPlugin, {
templateFormats: "md"
});
// RSS plugin
const pluginRss = require("@11ty/eleventy-plugin-rss");
eleventyConfig.addPlugin(pluginRss);
// Add filters to Nunjucks
eleventyConfig.addFilter("dateDisplay", require("./src/site/_filters/dates.js") );
eleventyConfig.addFilter("section", require("./src/site/_filters/section.js") );
eleventyConfig.addFilter("squash", require("./src/site/_filters/squash.js") );
eleventyConfig.addFilter("kebab", require("./src/site/_filters/kebab.js") );
// Assemble some collections
eleventyConfig.addCollection("tagList", require("./src/site/_filters/getTagList.js"));
eleventyConfig.addCollection("posts", function(collection) {
return collection.getFilteredByGlob("src/site/blog/*.md").reverse();
});
eleventyConfig.addCollection("cards", function(collection) {
return collection.getAll().filter(function(item) {
return "card" in item.data;
});
});
// static passthroughs
eleventyConfig.addPassthroughCopy("src/site/fonts");
eleventyConfig.addPassthroughCopy("src/site/images");
eleventyConfig.addPassthroughCopy("src/site/manifest.json");
eleventyConfig.addPassthroughCopy("src/site/browserconfig.xml");
eleventyConfig.addPassthroughCopy("src/site/CNAME");
// minify the html output
const htmlmin = require("html-minifier");
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
if( outputPath.endsWith(".html") ) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: false, // we need comments to identify the expcerpt split marker.
collapseWhitespace: true
});
return minified;
}
return content;
});
// Avoid orphans
eleventyConfig.addFilter("orphanWrap", function(text) {
if(!text) return;
let splitSpace = text.split(" ");
let after = "";
if(splitSpace.length > 2) {
after += " ";
let lastWord = splitSpace.pop();
let secondLastWord = splitSpace.pop();
after += `${secondLastWord} ${lastWord}`;
}
return splitSpace.join(" ") + after;
});
// other config settings
// make the prime target act like prod
env = (env=="prime") ? "prod" : env;
return {
dir: {
input: "src/site",
output: "dist",
data: `_data/${env}`
},
templateFormats : ["njk", "md"],
htmlTemplateEngine : "njk",
markdownTemplateEngine : "njk",
passthroughFileCopy: true
};
};