-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
92 lines (78 loc) · 2.39 KB
/
.eleventy.js
File metadata and controls
92 lines (78 loc) · 2.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
import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
const passthroughFiles = [
{ from: 'src/assets', to: 'assets' },
{ from: 'src/data/graph.json', to: 'data/graph.json' },
{ from: 'src/css', to: 'css' },
{ from: 'src/site.webmanifest', to: 'site.webmanifest' },
];
/** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */
export default function (eleventyConfig) {
eleventyConfig.setServerOptions({
showAllHosts: true,
});
for (let i = 0; i < passthroughFiles.length; i += 1) {
const entry = passthroughFiles[i];
eleventyConfig.addPassthroughCopy({ [entry.from]: entry.to });
}
eleventyConfig.addWatchTarget('src/css/');
eleventyConfig.addWatchTarget('src/js/');
eleventyConfig.addNunjucksFilter('dateIso', (value) => {
if (!value) {
return '';
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return '';
}
return date.toISOString().split('T')[0];
});
eleventyConfig.addNunjucksFilter('isExternalLink', (href) => {
if (!href) {
return false;
}
return href.startsWith('http://') || href.startsWith('https://') || href.startsWith('//');
});
eleventyConfig.addNunjucksFilter('getNodeDepth', (nodeId, graphData) => {
if (!graphData || !graphData.links) {
return 0;
}
// Build parent map - include both belongsTo and relates links
const parents = new Map();
for (const link of graphData.links) {
if (link.kind === 'belongsTo' || link.kind === 'relates') {
parents.set(link.target, link.source);
}
}
// Calculate depth
let depth = 0;
let current = nodeId;
while (parents.has(current)) {
current = parents.get(current);
depth += 1;
}
return depth;
});
eleventyConfig.addNunjucksFilter('findNodeById', (nodes, nodeId) => {
if (!nodes || !nodeId) {
return null;
}
return nodes.find(node => node.id === nodeId) || null;
});
eleventyConfig.addGlobalData('graphData', async () => {
const file = resolve('src/data/graph.json');
const content = await readFile(file, 'utf-8');
return JSON.parse(content);
});
return {
dir: {
input: 'src',
includes: '_includes',
data: '_data',
output: 'dist',
},
templateFormats: ['njk', 'md', '11ty.js'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
};
}