-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
.eleventy.js
64 lines (54 loc) · 1.7 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
module.exports = eleventyConfig => {
/**
* Not sure if this is actually needed :)
*/
eleventyConfig.addWatchTarget("content");
eleventyConfig.addPassthroughCopy("content/**/*.(png|jpg|webp|avif|css|js)");
/**
* Kirby stores metadata for assets in an additional content file
* Those content files should not be used by 11ty to create more
* subpages.
*/
eleventyConfig.ignores.add("content/**/*.(png|jpg|webp|avif).md");
/**
* The permalink feature is used to rewrite Kirby’s folders.
* Kirby uses sorting numbers in folder names. Those need to be removed.
* Kirby also uses different content file names to load specific templates.
* This is not compatible with 11ty's data file naming convention. But we can
* fix this by rewriting that to index.html instead.
*/
eleventyConfig.addGlobalData("permalink", () => {
return (data) => {
const dir = data.page.filePathStem;
const folders = dir.split("/");
/**
* Remove the last part. It’s Kirby’s content file name
* but will be mistaken in 11ty as yet another sub page.
*/
const path = folders.slice(0, -1);
/**
* Don't render anything inside a drafts folder
*/
if (path.includes("_drafts")) {
return false;
}
/**
* Remove Kirby's sorting numbers
*/
const permalink = path.map((folder) => {
if (folder.includes("_")) {
return folder.replace(/^([0-9]+_)/, "");
}
return folder;
});
return `${permalink.join("/")}/index.html`;
};
});
// Return your Object options:
return {
dir: {
input: "content",
includes: "../_includes"
}
}
};