-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
200 lines (178 loc) · 8.16 KB
/
Copy patheleventy.config.js
File metadata and controls
200 lines (178 loc) · 8.16 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItCheckbox = require("markdown-it-checkbox");
const path = require("path");
module.exports = function (eleventyConfig) {
// ── Plugins ──────────────────────────────────────────────────────────────
eleventyConfig.addPlugin(syntaxHighlight);
// ── Ignore non-content markdown docs ─────────────────────────────────────
eleventyConfig.ignores.add("README.md");
eleventyConfig.ignores.add("AGENTS.md");
eleventyConfig.ignores.add("BUILD_CHECKLIST.md");
eleventyConfig.ignores.add("site_description_and_requirements.md");
eleventyConfig.ignores.add("CLAUDE.md");
eleventyConfig.ignores.add("_plan/**");
eleventyConfig.ignores.add("node_modules/**");
eleventyConfig.ignores.add("_site/**");
eleventyConfig.ignores.add("src/css/**");
eleventyConfig.ignores.add("src/js/**");
eleventyConfig.ignores.add("src/icons/**");
eleventyConfig.ignores.add("src/_data/**");
eleventyConfig.ignores.add("src/scripts/**");
// ── Passthrough copies ────────────────────────────────────────────────────
eleventyConfig.addPassthroughCopy({ "src/css": "css" });
eleventyConfig.addPassthroughCopy({ "src/js": "js" });
eleventyConfig.addPassthroughCopy({ "src/icons": "icons" });
eleventyConfig.addPassthroughCopy({ "src/manifest.json": "manifest.json" });
eleventyConfig.addPassthroughCopy({ "src/service-worker.js": "service-worker.js" });
eleventyConfig.addPassthroughCopy({ "src/robots.txt": "robots.txt" });
eleventyConfig.addPassthroughCopy({ "src/favicon.ico": "favicon.ico" });
eleventyConfig.addPassthroughCopy({ "src/favicon.svg": "favicon.svg" });
eleventyConfig.addPassthroughCopy({ "src/og-image.png": "og-image.png" });
eleventyConfig.addPassthroughCopy({ "src/a6f9053bdafb0276b849024ecb0d03ac.txt": "a6f9053bdafb0276b849024ecb0d03ac.txt" });
// ── Markdown-it configuration ─────────────────────────────────────────────
const md = markdownIt({
html: true,
linkify: true,
typographer: true,
})
.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.headerLink(),
level: [2, 3, 4],
slugify: (s) =>
s
.toLowerCase()
.replace(/[^\w\s-]/g, "")
.trim()
.replace(/\s+/g, "-"),
})
.use(markdownItCheckbox, {
divWrap: false,
divClass: "checkbox-item",
idPrefix: "cb-",
});
// Custom fence renderer — wrap code blocks and convert ```mermaid
const defaultFence = md.renderer.rules.fence || function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};
md.renderer.rules.fence = function (tokens, idx, options, env, self) {
const token = tokens[idx];
const lang = token.info.trim();
if (lang === "mermaid") {
return `<div class="mermaid">${md.utils.escapeHtml(token.content)}</div>\n`;
}
const rendered = defaultFence(tokens, idx, options, env, self);
// Wrap in a div for the copy button
const langClass = lang ? ` data-lang="${lang}"` : "";
return `<div class="code-block-wrapper"${langClass}>${rendered}</div>`;
};
// Wrap tables for horizontal scroll
md.renderer.rules.table_open = function () {
return '<div class="table-scroll"><table>';
};
md.renderer.rules.table_close = function () {
return "</table></div>";
};
eleventyConfig.setLibrary("md", md);
// ── Collections ───────────────────────────────────────────────────────────
eleventyConfig.addCollection("sections", (api) =>
api.getFilteredByGlob("content/*/index.md")
.sort((a, b) => a.fileSlug.localeCompare(b.fileSlug))
);
eleventyConfig.addCollection("subsections", (api) =>
api.getFilteredByGlob("content/*/*/index.md")
.sort((a, b) => a.fileSlug.localeCompare(b.fileSlug))
);
eleventyConfig.addCollection("articles", (api) =>
api.getFilteredByGlob("content/*/*/*/index.md")
.sort((a, b) => a.fileSlug.localeCompare(b.fileSlug))
);
// ── Filters ───────────────────────────────────────────────────────────────
// Return subsections belonging to a given section URL prefix
eleventyConfig.addFilter("subsectionsFor", function (subsections, sectionUrl) {
return subsections.filter((s) => {
const parts = s.url.replace(/^\/|\/$/g, "").split("/");
return parts.length === 2 && s.url.startsWith(sectionUrl);
});
});
// Return articles belonging to a given subsection URL prefix
eleventyConfig.addFilter("articlesFor", function (articles, subsectionUrl) {
return articles.filter((a) => a.url.startsWith(subsectionUrl) && a.url !== subsectionUrl);
});
// Remove the first H1 from rendered HTML (used in layouts that render title separately)
eleventyConfig.addFilter("removeH1", function (htmlContent) {
return htmlContent.replace(/<h1\b[^>]*>.*?<\/h1>/is, "").trimStart();
});
// Derive parent URL by stripping the last path segment
eleventyConfig.addFilter("parentUrl", function (url) {
const parts = url.replace(/\/$/, "").split("/");
parts.pop();
return parts.join("/") + "/";
});
// Depth of a URL path (number of real segments, e.g. "/" = 0, "/a/" = 1, "/a/b/" = 2)
eleventyConfig.addFilter("urlDepth", (url) =>
url.replace(/^\/|\/$/g, "").split("/").filter(Boolean).length
);
// Safe JSON serialisation for use inside <script type="application/ld+json">
// Escapes <, >, & so the JSON string is safe inside an HTML document.
eleventyConfig.addFilter("json", (val) =>
JSON.stringify(val)
.replace(/&/g, "\\u0026")
.replace(/</g, "\\u003c")
.replace(/>/g, "\\u003e")
);
// Slugify a title for use in IDs
eleventyConfig.addFilter("slugify", (str) =>
str
.toLowerCase()
.replace(/[^\w\s-]/g, "")
.trim()
.replace(/\s+/g, "-")
);
eleventyConfig.addFilter("slugify", (str) =>
str
.toLowerCase()
.replace(/[^\w\s-]/g, "")
.trim()
.replace(/\s+/g, "-")
);
// Extract breadcrumb segments from a URL
eleventyConfig.addFilter("breadcrumbs", function (url) {
const parts = url.replace(/^\/|\/$/g, "").split("/").filter(Boolean);
const crumbs = [{ label: "Home", url: "/" }];
let built = "";
for (const part of parts) {
built += "/" + part;
// Convert slug to title
const label = part
.split("-")
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
.join(" ");
crumbs.push({ label, url: built + "/" });
}
return crumbs;
});
// Return sitemap-ready page list
eleventyConfig.addCollection("sitemap", (api) =>
api.getAll().filter((p) => p.url && !p.url.includes("404") && !p.url.includes("/offline/"))
);
// ── Shortcodes ────────────────────────────────────────────────────────────
eleventyConfig.addShortcode("year", () => String(new Date().getFullYear()));
eleventyConfig.addFilter("htmlDateString", (date) => {
if (!date) return "";
return new Date(date).toISOString().split("T")[0];
});
// ── Directory config ──────────────────────────────────────────────────────
return {
dir: {
input: ".",
output: "_site",
includes: "src/_includes",
data: "src/_data",
},
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
templateFormats: ["njk", "md", "html"],
};
};