-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.eleventy.js
116 lines (95 loc) · 3.47 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
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
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const pluginTOC = require("eleventy-plugin-toc")
const lucideIcons = require("@grimlink/eleventy-plugin-lucide-icons");
const md = new markdownIt({ html: true });
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy({
"src/media": "/media",
"src/assets": "/",
"node_modules/alpinejs/dist/cdn.min.js": "js/alpine.js",
"node_modules/htmx.org/dist/htmx.min.js": "js/htmx.js"
});
eleventyConfig.addShortcode("now", () => `${Date.now()}`);
eleventyConfig.addPlugin(lucideIcons);
eleventyConfig.setLibrary("md", markdownIt({ html: true }).use(markdownItAnchor, { tabIndex: false }));
eleventyConfig.addFilter("markdown", (content) => {
return md.render(content);
});
eleventyConfig.addPlugin(pluginTOC, {
tags: ['h2', 'h3'],
});
eleventyConfig.addFilter("sortByOrderAndTitle", (values) => {
let vals = [...values];
return vals.sort((a, b) => {
// Sort by order first
const aOrder = typeof a.data.order === 'number' ? a.data.order : 0;
const bOrder = typeof b.data.order === 'number' ? b.data.order : 0;
const orderDiff = aOrder - bOrder;
if (orderDiff !== 0) return orderDiff;
// If order is the same, sort by title
return a.data.title.localeCompare(b.data.title);
})
});
eleventyConfig.addFilter("sortByUrl", (values) => {
let vals = [...values];
return vals.sort((a, b) => Math.sign(a.url.localeCompare(b.url)));
});
eleventyConfig.addNunjucksFilter("getNextPrevMenu", function(menu, currentUrl) {
let flatMenu = [];
menu.forEach(item => {
flatMenu.push(item);
if (item.children) {
item.children.forEach(child => {
flatMenu.push(child);
});
}
});
const currentIndex = flatMenu.findIndex(item => item.url === currentUrl);
const previousItem = currentIndex > 0 ? flatMenu[currentIndex - 1] : null;
const nextItem = currentIndex < flatMenu.length - 1 ? flatMenu[currentIndex + 1] : null;
return { previous: previousItem, next: nextItem };
});
eleventyConfig.addCollection("menu", function(collectionApi) {
const docs = collectionApi.getFilteredByGlob("src/docs/**/*.md");
let menu = [];
docs.sort((a, b) => {
// Sort by order first
const aOrder = typeof a.data.order === 'number' ? a.data.order : 0;
const bOrder = typeof b.data.order === 'number' ? b.data.order : 0;
const orderDiff = aOrder - bOrder;
if (orderDiff !== 0) return orderDiff;
// If order is the same, sort by title
return a.data.title.localeCompare(b.data.title);
})
.forEach(doc => {
const urlSegments = doc.url.split('/').filter(Boolean);
// Add top-level items
if (urlSegments.length === 1 || urlSegments.length === 2) {
let menuItem = {
title: doc.data.title,
url: doc.url,
children: []
};
// Add children
docs.forEach(subDoc => {
const subUrlSegments = subDoc.url.split('/').filter(Boolean);
if (subUrlSegments.length === 3 && subUrlSegments[1] === urlSegments[1]) {
menuItem.children.push({
title: subDoc.data.title,
url: subDoc.url
});
}
});
menu.push(menuItem);
}
});
return menu;
});
return {
dir: {
input: "src",
output: "_site"
}
}
};