-
Notifications
You must be signed in to change notification settings - Fork 40
/
eleventy.config.js
111 lines (92 loc) · 3.15 KB
/
eleventy.config.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
const { EleventyEdgePlugin } = require("@11ty/eleventy");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const uglify = require("uglify-js");
const sass = require("sass");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(EleventyEdgePlugin);
// syntax highlighting plugin
eleventyConfig.addPlugin(syntaxHighlight, {
templateFormats: ["md"]
});
// RSS plugin
eleventyConfig.addPlugin(pluginRss);
// Sass pipeline
eleventyConfig.addTemplateFormats("scss");
eleventyConfig.addExtension("scss", {
outputFileExtension: "css",
compile: function(contents, includePath) {
let includePaths = [this.config.dir.includes];
return () => {
let ret = sass.renderSync({
file: includePath,
includePaths,
data: contents,
outputStyle: "compressed"
});
return ret.css.toString("utf8");
}
}
});
// JS pipeline. Just minify.
eleventyConfig.addTemplateFormats("js");
eleventyConfig.addExtension("js", {
outputFileExtension: "js",
compile: function(contents) {
return (data) => {
const min = uglify.minify(
contents, {}
);
return min.code;
}
}
});
// Add filters and shortcodes
eleventyConfig.addShortcode("socialLink", require("./src/site/_filters/socialLink.js") );
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");
// 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"
},
templateFormats : ["njk", "md"],
htmlTemplateEngine : "njk",
markdownTemplateEngine : "njk",
passthroughFileCopy: true
};
};