-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
94 lines (80 loc) · 3.04 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
const less = require("less");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const PRISM_LANGUAGE_SCM = require("./plugins/prism-language-scm.js");
module.exports = (eleventyConfig) => {
eleventyConfig.setServerOptions({
// Prevent the server from trying to do a clever hot-reload when only
// Markdown is changed. We have JavaScript code that needs to react to
// changed content, so it's better to reload the page instead.
domDiff: false
});
eleventyConfig.addPlugin(syntaxHighlight, {
init({ Prism }) {
Prism.languages.scm = PRISM_LANGUAGE_SCM;
}
});
// Add custom templates
eleventyConfig.addTemplateFormats("less");
eleventyConfig.addExtension("less", {
outputFileExtension: "css",
compile: async function (input, inputPath) {
try {
const output = await less.render(input, {
math: "always" // required for use with Skeleton
});
this.addDependencies(inputPath, output.imports);
return async () => output.css;
} catch(err) {
console.error(`Error compiling less:\n`, err);
throw err;
}
}
});
eleventyConfig.addTemplateFormats("js");
eleventyConfig.addExtension("js", require("./plugins/terser.js"));
eleventyConfig.setLibrary("md", require("./plugins/markdown-it.js"));
// Add passthrough file copies
// copy the data from static to static
eleventyConfig.addPassthroughCopy({ "static": "static" });
// Ensure the CNAME file is in the root dir
eleventyConfig.addPassthroughCopy({ "static/CNAME": "CNAME" });
eleventyConfig.addPassthroughCopy({ "assets": "assets" });
// Add our custom collection of blog posts
eleventyConfig.addCollection("blog-posts", (collectionApi) => {
return collectionApi.getFilteredByGlob("blog/posts/*.md").reverse();
});
eleventyConfig.addWatchTarget("./less/");
eleventyConfig.addWatchTarget("./layouts/");
// Since 11ty doesn't natively provide EJS with filters, we have to manually
// define our helpers like this. In a magical way found by @savetheclocktower
globalThis.helpers = {
// Add a function to allow extraction of the text before `<!-- more -->`
// in blog posts, to maintain compatibility with our old blog system summaries
findPostSummary: (value) => {
if (typeof value !== "string") {
return "";
}
if (!value.includes("<!-- more -->")) {
// If the post for some reason doesn't include this summary delimiter
return "";
}
const summary = value.split("<!-- more -->")[0];
return summary ?? "";
}
};
// return config
return {
markdownTemplateEngine: false,
// ^^ We can't parse md in liquidjs or njk, because our docs seem to have
// naturally occurring instances of both of their delimiters.
// So for now we will just disable any templating on markdown
dir: {
input: "blog",
output: "_dist",
includes: "less",
// Below values are relative to the `./docs` folder
layouts: "../layouts",
data: "../data"
}
};
};