-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
85 lines (68 loc) · 2.32 KB
/
eleventy.config.js
File metadata and controls
85 lines (68 loc) · 2.32 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
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
import esbuild from "esbuild";
import path from "node:path";
import * as sass from "sass";
// Function to check if a value has a tag
function hasTag(value, tag) {
return Array.isArray(value.tags) && value.tags.includes(tag);
}
// Function to select values in an array based on whether they have a tag
function selectTag(array, tag) {
return array.filter(item => hasTag(item, tag));
}
// Function to resolve a link with the specified data
function resolveLink(value, data) {
if (typeof value !== 'string' || data === undefined)
return value;
return value.startsWith("@") ? data[value.substring(1)] : value;
}
// Function to compile SCSS files
function compileSCSS(inputContent, inputPath) {
let parsed = path.parse(inputPath);
if (!parsed.name.startsWith("index"))
return;
let result = sass.compileString(inputContent, {
loadPaths: [
parsed.dir || ".",
this.config.dir.includes,
"./node_modules",
]
});
this.addDependencies(inputPath, result.loadedUrls);
return async () => result.css;
}
// Function to compile JavaScript files
async function compileJS(inputContent, inputPath) {
let parsed = path.parse(inputPath);
if (!parsed.name.startsWith("index"))
return;
let result = await esbuild.build({
target: 'es2020',
entryPoints: [inputPath],
minify: true,
bundle: true,
write: false,
});
return async () => result.outputFiles[0].text;
}
// Export the Eleventy configuration
export const config = {
htmlTemplateEngine: "njk",
};
// Adjust the configuration
export default async function (eleventyConfig) {
// Set the directories
eleventyConfig.setInputDirectory("src");
eleventyConfig.setLayoutsDirectory("_layouts");
// Add passthrough copies
eleventyConfig.addPassthroughCopy("assets");
// Add custom template handling
eleventyConfig.addExtension("scss", { outputFileExtension: "css", useLayouts: false, compile: compileSCSS });
eleventyConfig.addExtension("js", { outputFileExtension: "js", useLayouts: false, compile: compileJS });
eleventyConfig.addTemplateFormats(["scss", "js"]);
// Add custom template filters
eleventyConfig.addFilter("keys", value => Object.keys(value));
eleventyConfig.addFilter("values", value => Object.values(value));
eleventyConfig.addFilter("hastag", hasTag);
eleventyConfig.addFilter("selecttag", selectTag);
eleventyConfig.addFilter("resolvelink", resolveLink);
};