-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.eleventy.js
102 lines (91 loc) · 3.1 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const fs = require("fs/promises");
module.exports = function (eleventyConfig) {
// copy files
eleventyConfig.addPassthroughCopy("src/results/manifest.json");
eleventyConfig.addPassthroughCopy("src/results/pwabuilder-sw.js");
eleventyConfig.addPassthroughCopy("_redirects");
// eleventyConfig.addPassthroughCopy("cache");
eleventyConfig.on("eleventy.after", async (arg) => {
// don't run on serverless requests
if (process.env.ELEVENTY_SERVERLESS) return;
await fs.cp("./cache/", "./_site/cache/", {
recursive: true,
});
});
// these assets are handled by esbuild
// eleventyConfig.addPassthroughCopy("src/preview/assets");
// eleventyConfig.addPassthroughCopy("src/images");
// if (process.env.ELEVENTY_PRODUCTION) {
// eleventyConfig.addPassthroughCopy("data");
// }
// enable async functions
eleventyConfig.addNunjucksAsyncFilter("await", async (promise, callback) => {
try {
const result = await promise;
callback(null, result);
} catch (error) {
callback(error);
}
});
// add serverless plugin
const { EleventyServerlessBundlerPlugin } = require("@11ty/eleventy");
const redirectHandler = require("./utils/redirectHandlers.js");
// add cascade data filter selectors for serverless functions
eleventyConfig.dataFilterSelectors.add("headers");
// base serverless config
const serverlessConfig = {
functionsDir: "./serverless/",
copy: ["./utils/", "./cache/", "./data/"],
excludeDependencies: [
"color-contrast-calc",
"extract-colors",
"chroma-js",
"simple-git",
],
};
// on demand builders for tournament results/superscore pages
eleventyConfig.addPlugin(EleventyServerlessBundlerPlugin, {
...serverlessConfig,
name: "odb",
redirects: redirectHandler({ odb: true, force: false }),
});
// dynamic handler for POST requests for sciolyff previewer
eleventyConfig.addPlugin(EleventyServerlessBundlerPlugin, {
...serverlessConfig,
name: "dynamicpost",
redirects: redirectHandler({ odb: false, force: true }),
});
// minify html
const htmlmin = require("html-minifier-terser");
eleventyConfig.addTransform("htmlmin", function (content) {
if (this.outputPath && this.outputPath.endsWith(".html")) {
const minified = htmlmin.minify(content, {
// collapseBooleanAttributes: true,
collapseWhitespace: true,
conservativeCollapse: true,
// removeComments: true,
// sortAttributes: true,
// sortClassName: true,
// useShortDoctype: true,
minifyCSS: this.outputPath.includes("/preview/"),
minifyJS: this.outputPath.includes("/preview/"),
});
return minified;
} else if (
this.inputPath.endsWith("template.njk") ||
this.inputPath.endsWith("superscore.njk") ||
this.inputPath.endsWith("render.njk") ||
(this.outputPath && this.outputPath.endsWith("tournaments.json"))
) {
return content.replace(/\s+/g, " ");
}
return content;
});
return {
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dir: {
input: "src",
},
};
};