-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
76 lines (62 loc) · 2.3 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
const path = require("path");
const browserslist = require("browserslist");
const { bundle, browserslistToTargets, features, composeVisitors } = require("lightningcss");
const responsiveImgs = require("./src/_plugins/responsive.images.js");
module.exports = function (eleventyConfig) {
const now = new Date();
process.env.TZ = "UTC";
eleventyConfig.setTemplateFormats("md,njk,html");
// Recognize CSS as a "template language"
eleventyConfig.addTemplateFormats("css");
// Process CSS with LightningCSS
eleventyConfig.addExtension("css", {
outputFileExtension: "css",
compile: async function (_inputContent, inputPath) {
let parsed = path.parse(inputPath);
if (parsed.name.startsWith("_")) {
return;
}
let targets = browserslistToTargets(browserslist("> 0.2% and not dead"));
return async () => {
// Switch to the `transform` function if you don't
// plan to use `@import` to merge files
let { code } = await bundle({
filename: inputPath,
minify: true,
sourceMap: false,
targets,
// Supports CSS nesting
// drafts: {
// features.nesting,
// },
});
return code;
};
},
});
eleventyConfig.addFilter("cachebust", (url) => {
const params = new URLSearchParams();
try {
params.set("v", now.getTime());
} catch (error) {}
return `${url}?${params}`;
});
// Assets
eleventyConfig.addPassthroughCopy("src/img");
eleventyConfig.addPassthroughCopy("src/fonts");
eleventyConfig.addPassthroughCopy({ "src/public": "/" });
eleventyConfig.setServerOptions({
watch: ["_site/*.css"],
});
eleventyConfig.addAsyncShortcode("image", responsiveImgs.rimage);
// collections
eleventyConfig.addCollection("sites", function (collectionApi) {
return collectionApi
.getFilteredByGlob("./src/sites/*.md")
.sort((a, b) => b.data.order - a.data.order)
.reverse();
});
return {
dir: { input: "src", output: "_site" },
};
};