-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy path.eleventy.js
More file actions
51 lines (44 loc) · 1.49 KB
/
.eleventy.js
File metadata and controls
51 lines (44 loc) · 1.49 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
const yaml = require("js-yaml");
module.exports = (eleventyConfig) => {
eleventyConfig.addShortcode("currentYear", () => new Date().getFullYear());
// Add this line to copy your external assets
eleventyConfig.addPassthroughCopy("src/assets");
// 1. Recognize YAML as a template format
eleventyConfig.addTemplateFormats("yaml");
// 2. Define how to process YAML files
eleventyConfig.addExtension("yaml", {
key: "yaml",
compile: async (inputContent) => {
const data = yaml.load(inputContent);
return async () => {
// This returns the 'content' for the page (the bio)
return data.bio || "";
};
},
getData: async (inputPath) => {
const fs = require("fs/promises");
const content = await fs.readFile(inputPath, "utf-8");
return yaml.load(content);
},
});
// 2. The Randomized Collection
eleventyConfig.addCollection("randomPeople", (collectionApi) => {
// Grab all yaml files from the users folder
const people = collectionApi.getFilteredByGlob("src/users/*.yaml");
// Create a copy of the array to avoid mutating the original global collection
const shuffled = [...people];
// Fisher-Yates Shuffle
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
});
return {
dir: {
input: "src",
output: "_site",
includes: "_includes",
},
};
};