forked from inveniosoftware/inveniosoftware.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
121 lines (102 loc) · 3.39 KB
/
eleventy.config.js
File metadata and controls
121 lines (102 loc) · 3.39 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import fs from "node:fs";
import eleventySass from "@11tyrocks/eleventy-plugin-sass-lightningcss";
import eleventyNavigation from "@11ty/eleventy-navigation";
import pluginRss from "@11ty/eleventy-plugin-rss";
export default async function (eleventyConfig) {
// copy all `src/assets` to `_site/static"
eleventyConfig.addPassthroughCopy({ "src/assets/images": "assets/images" });
// enable SASS/SCSS
eleventyConfig.addPlugin(eleventySass);
// navigation menu support
eleventyConfig.addPlugin(eleventyNavigation);
eleventyConfig.addFilter("divideArrayInParts", (arr, n) => {
const result = Array.from({ length: n }, () => []);
arr.forEach((item, index) => {
result[index % n].push(item);
});
return result;
});
eleventyConfig.addFilter("sliceArray", (arr, n) => {
const result = [];
for (let i = 0; i < arr.length; i += n) {
result.push(arr.slice(i, i + n));
}
return result;
});
eleventyConfig.addFilter("sortBy", (arr, field, filterField, filterValue) => {
let result = [...arr];
if (filterField && filterValue) {
result = result.filter((item) => item[filterField] === filterValue);
}
return result.sort((a, b) => a[field].localeCompare(b[field]));
});
eleventyConfig.addFilter("dateFormat", (date) => {
const d = new Date(date);
const months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
return `${months[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;
});
// Sort showcase items: featured first, then alphabetical, remove duplicates
eleventyConfig.addFilter("sortShowcaseItems", (items) => {
if (!Array.isArray(items)) return items;
// Remove duplicates based on name and URL combination
// const uniqueItems = items.filter((item, index, self) =>
// index === self.findIndex(t => t.name === item.name && t.url === item.url)
// );
// Sort: featured items first, then alphabetical by name
const sorted = items.sort((a, b) => {
// Featured items come first
if (a.featured && !b.featured) return -1;
if (!a.featured && b.featured) return 1;
// Within same featured status, sort alphabetically by name
return a.name.localeCompare(b.name);
});
return sorted;
});
eleventyConfig.addFilter("startswith", (input, prefix) => {
if (typeof input !== "string" || typeof prefix !== "string") return false;
return input.startsWith(prefix);
});
// Format authors array with comma separation
eleventyConfig.addFilter("formatAuthors", (authorKeys, authorsData) => {
if (!Array.isArray(authorKeys) || !authorsData) return "";
const authorNames = authorKeys
.map((key) => authorsData[key]?.name)
.filter((name) => name); // Remove empty names
return authorNames.join(", ");
});
// RSS feed
eleventyConfig.addPlugin(pluginRss, {
htmlBasePluginOptions: {
baseHref: "",
},
});
// embed SVGs
eleventyConfig.addShortcode("svgImg", async (filepath) => {
return fs.readFileSync(`src/${filepath}`, "utf8");
});
}
export const config = {
templateFormats: ["md", "njk", "html", "liquid", "11ty.js"],
markdownTemplateEngine: "liquid",
dataTemplateEngine: "liquid",
htmlTemplateEngine: "liquid",
dir: {
input: "src",
includes: "_includes",
data: "_data",
output: "_site",
},
};