-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eleventy.js
54 lines (49 loc) · 1.85 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
const PATH = require("node:path");
const babel = require("@babel/core");
const prettier = require("prettier");
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("docs/_headers");
eleventyConfig.addPassthroughCopy("docs/index.html");
eleventyConfig.addPassthroughCopy("docs/template.html");
eleventyConfig.addPassthroughCopy("docs/**/*.css");
eleventyConfig.addPassthroughCopy("docs/**/*.csv");
eleventyConfig.addPassthroughCopy("docs/**/*.json");
eleventyConfig.addPassthroughCopy("docs/**/*.md");
eleventyConfig.addPassthroughCopy("docs/**/*.png");
/**
* Not familiar with eleventy, but it seems to not rewrite the whole build folder,
* which lead to not having the js files in the build folder on the first build.
*/
eleventyConfig.addPassthroughCopy("docs/**/*.js");
eleventyConfig.addWatchTarget("docs/**/*.js");
/**
* printFileContents
*
* This shortcode is used to print the contents of a JavaScript file (or any
* file, for that matter) into a template. It takes the content of what is
* exported using "modules.export = …" and prints it verbatim.
*/
eleventyConfig.addShortcode("printFileContents", function (relativePath) {
const path = PATH.join(__dirname, PATH.dirname(this.page.inputPath), relativePath);
const { code } = babel.transformFileSync(path, {
sourceType: "script",
generatorOpts: {
compact: false,
retainLines: true,
shouldPrintComment: (val) => !/^\s*global\s/.test(val),
},
});
return code;
});
eleventyConfig.addTransform("prettify", (content, outputPath) =>
outputPath.endsWith(".html") ? prettier.format(content, { parser: "html" }) : content
);
return {
dir: {
input: "docs",
output: "build",
},
htmlTemplateEngine: "njk",
templateFormats: ["html", "njk", "11ty.js"],
};
};