-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path.eleventy.js
More file actions
70 lines (59 loc) · 2.27 KB
/
Copy path.eleventy.js
File metadata and controls
70 lines (59 loc) · 2.27 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
const yaml = require("js-yaml");
module.exports = function(eleventyConfig) {
// Enable YAML data files (.yaml)
eleventyConfig.addDataExtension("yaml", (contents) => yaml.load(contents));
eleventyConfig.addPassthroughCopy("assets");
// Collection: people (built from the directory, so the marker tag doesn't
// leak into each person's research `tags`)
eleventyConfig.addCollection("people", (collectionApi) =>
collectionApi.getFilteredByGlob("src/people/*.md")
);
// Filter: limit array length
eleventyConfig.addFilter("limit", (arr, limit) =>
Array.isArray(arr) ? arr.slice(0, limit) : []
);
// Filter: sort by date field descending
eleventyConfig.addFilter("sortByDate", (arr) => {
if (!Array.isArray(arr)) return [];
return [...arr].sort((a, b) => new Date(b.date) - new Date(a.date));
});
// Filter: filter active projects
eleventyConfig.addFilter("active", (arr) => {
if (!Array.isArray(arr)) return [];
return arr.filter(p => p.active !== false);
});
// Filter: filter featured projects
eleventyConfig.addFilter("featured", (arr) => {
if (!Array.isArray(arr)) return [];
return arr.filter(p => p.featured === true);
});
// Filter: people collection entries with a given role, sorted by `order` then name
eleventyConfig.addFilter("byRole", (coll, role) => {
return (coll || [])
.filter(p => p.data.role === role)
.sort((a, b) =>
((a.data.order ?? 99) - (b.data.order ?? 99)) ||
a.data.name.localeCompare(b.data.name)
);
});
// Shortcode: current year (footer copyright)
eleventyConfig.addShortcode("year", () => String(new Date().getFullYear()));
// Filter: "Jana Pavlasek" -> "JP" (photo placeholder)
eleventyConfig.addFilter("initials", (name) => {
return (name || "").split(/\s+/).map(w => w[0]).filter(Boolean).slice(0, 2).join("").toUpperCase();
});
return {
// GitHub Pages project sites live under /<repo>/ — the deploy workflow
// sets PATH_PREFIX; locally it defaults to "/".
pathPrefix: process.env.PATH_PREFIX || "/",
dir: {
input: "src",
includes: "../_includes",
data: "../_data",
output: "_site"
},
templateFormats: ["njk", "html", "md"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk"
};
};