Repository navigation
Expand file tree
/
Copy patheleventy.config.js
More file actions
44 lines (39 loc) · 1.55 KB
/
Copy patheleventy.config.js
File metadata and controls
44 lines (39 loc) · 1.55 KB
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
import { createHash } from "node:crypto";
import { readFileSync } from "node:fs";
import { join } from "node:path";
export default function (eleventyConfig) {
// Passthrough copy for assets (css, js, images). JS is copied by glob
// (not the whole directory) so the Datadog RUM source map
// (src/assets/js/rum-init.js.map) is never published to GitHub Pages:
// it is generated by `npm run bundle:rum` and uploaded to Datadog with
// `npm run upload:sourcemaps` instead.
eleventyConfig.addPassthroughCopy("src/assets/css");
eleventyConfig.addPassthroughCopy("src/assets/data");
eleventyConfig.addPassthroughCopy("src/assets/img");
eleventyConfig.addPassthroughCopy("src/assets/js/*.js");
// Passthrough copy for root-level files
eleventyConfig.addPassthroughCopy({
"src/robots.txt": "robots.txt",
"src/.nojekyll": ".nojekyll"
});
// Cache-busting: append a short content hash to local asset URLs so
// pushes are picked up immediately instead of serving stale cached copies.
// Zero-pad a number to two digits (e.g. 5 -> "05") for design stats/numbering.
eleventyConfig.addFilter("pad2", (n) => String(n).padStart(2, "0"));
eleventyConfig.addFilter("cacheBust", (url) => {
try {
const file = join("src", String(url).replace(/^\//, "").split("?")[0]);
const hash = createHash("md5").update(readFileSync(file)).digest("hex").slice(0, 8);
return `${url}?v=${hash}`;
} catch {
return url;
}
});
return {
dir: {
input: "src",
output: "docs",
includes: "_includes",
},
};
}