-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
40 lines (34 loc) · 1.3 KB
/
.eleventy.js
File metadata and controls
40 lines (34 loc) · 1.3 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
const fs = require("fs");
const path = require("path");
function loadJsonDir(dir) {
const full = path.join(__dirname, "src", dir);
const files = fs.readdirSync(full).filter(f => f.endsWith(".json"));
return files.map(f => {
const raw = fs.readFileSync(path.join(full, f), "utf-8");
const obj = JSON.parse(raw);
if (!obj.slug) obj.slug = f.replace(/\.json$/, "");
return obj;
}).sort((a,b) => (a.title||"").localeCompare(b.title||""));
}
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({ "src/assets": "assets" });
eleventyConfig.addPassthroughCopy({ "src/admin": "admin" });
eleventyConfig.addCollection("projects", () => {
const items = loadJsonDir("content/projects");
return items.map(i => ({ ...i, url: `/projects/${i.slug}/` }));
});
eleventyConfig.addCollection("tools", () => {
const items = loadJsonDir("content/tools");
return items.map(i => ({ ...i, url: `/tools/${i.slug}/` }));
});
eleventyConfig.addCollection("datasets", () => {
const items = loadJsonDir("content/datasets");
return items.map(i => ({ ...i, url: `/datasets/${i.slug}/` }));
});
return {
dir: { input: "src", output: "dist" },
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
templateFormats: ["njk", "html", "md"]
};
};