-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.eleventy.js
More file actions
347 lines (326 loc) · 13.2 KB
/
Copy path.eleventy.js
File metadata and controls
347 lines (326 loc) · 13.2 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const fs = require("fs");
const crypto = require("crypto");
const path = require("path");
const Prism = require("prismjs");
// Prism ships no grammar for these component-file formats, and without one the
// syntax-highlight plugin passes the fence body through *unescaped* — the sample
// markup then parses as real HTML (tags vanish, `<a href>` becomes a live link).
// They are all markup supersets, so alias them onto Prism's markup grammar.
for (const lang of ["svelte", "vue", "astro"]) {
Prism.languages[lang] = Prism.languages.markup;
}
module.exports = function (eleventyConfig) {
// Plugins
eleventyConfig.addPlugin(syntaxHighlight);
// Markdown configuration
const md = markdownIt({
html: true,
linkify: true,
typographer: true,
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.headerLink(),
slugify: (s) =>
s
.toLowerCase()
.replace(/[^\w\s-]/g, "")
.replace(/\s+/g, "-")
.replace(/-+/g, "-")
.trim(),
});
// Wrap every table in a horizontally-scrollable container so wide tables
// never force the page to overflow on narrow (mobile) viewports.
md.renderer.rules.table_open = () => '<div class="table-wrap">\n<table>\n';
md.renderer.rules.table_close = () => '</table>\n</div>\n';
eleventyConfig.setLibrary("md", md);
// Passthrough copies
eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.addPassthroughCopy("manifest.json");
eleventyConfig.addPassthroughCopy("sw.js");
eleventyConfig.addPassthroughCopy("favicon.ico");
eleventyConfig.addPassthroughCopy("robots.txt");
eleventyConfig.addPassthroughCopy("_headers");
eleventyConfig.addPassthroughCopy("526c8500ed2fb949afa6b936dff3880d.txt");
// Collections — one per topic area
eleventyConfig.addCollection("topic_core", (collection) =>
collection
.getFilteredByGlob(
"content/core-browser-loading-mechanics-priority-queues/**/*.md"
)
.sort((a, b) => a.url.localeCompare(b.url))
);
eleventyConfig.addCollection("topic_hints", (collection) =>
collection
.getFilteredByGlob(
"content/resource-hint-implementation-preloading-strategies/**/*.md"
)
.sort((a, b) => a.url.localeCompare(b.url))
);
eleventyConfig.addCollection("topic_http", (collection) =>
collection
.getFilteredByGlob(
"content/http2-http3-multiplexing-connection-optimization/**/*.md"
)
.sort((a, b) => a.url.localeCompare(b.url))
);
eleventyConfig.addCollection("topic_frameworks", (collection) =>
collection
.getFilteredByGlob(
"content/framework-specific-loading-strategies/**/*.md"
)
.sort((a, b) => a.url.localeCompare(b.url))
);
eleventyConfig.addCollection("allContent", (collection) =>
collection
.getFilteredByGlob("content/**/*.md")
.sort((a, b) => a.url.localeCompare(b.url))
);
// Asset hash filter — appends ?v=<8-char md5> so immutable-cached assets
// are busted automatically whenever the file content changes.
eleventyConfig.addFilter("assetHash", (url) => {
try {
const filePath = path.join(__dirname, url.replace(/^\//, "").split("?")[0]);
const hash = crypto.createHash("md5").update(fs.readFileSync(filePath)).digest("hex").slice(0, 8);
return `${url}?v=${hash}`;
} catch {
return url;
}
});
// Filters
eleventyConfig.addFilter("slugify", (str) =>
str
.toLowerCase()
.replace(/[^\w\s-]/g, "")
.replace(/\s+/g, "-")
.replace(/-+/g, "-")
.trim()
);
eleventyConfig.addFilter("absoluteUrl", (url, base) => {
try {
return new URL(url, base).toString();
} catch {
return url;
}
});
// Truncate filter for meta descriptions
eleventyConfig.addFilter("truncate", (str, len = 160) => {
if (!str) return "";
const plain = str.replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
return plain.length > len ? plain.slice(0, len - 1) + "…" : plain;
});
// Build year filter
eleventyConfig.addFilter("year", () => new Date().getFullYear());
// ISO date filter for JSON-LD / sitemap
eleventyConfig.addFilter("isoDate", (date) => {
if (!date) return new Date().toISOString().split("T")[0];
return new Date(date).toISOString().split("T")[0];
});
// URL depth (number of path segments)
eleventyConfig.addFilter("urlDepth", (url) => {
return url.split("/").filter(Boolean).length;
});
// Parent URL (one level up)
eleventyConfig.addFilter("urlParent", (url) => {
const parts = url.split("/").filter(Boolean);
if (parts.length <= 1) return "/";
parts.pop();
return "/" + parts.join("/") + "/";
});
// Check if URL starts with another URL
eleventyConfig.addFilter("urlStartsWith", (url, prefix) => {
return url.startsWith(prefix);
});
// Breadcrumb filter — derives crumbs from a URL
eleventyConfig.addFilter("breadcrumbs", (url) => {
const parts = url.split("/").filter(Boolean);
const crumbs = [{ label: "Home", url: "/" }];
let current = "";
const labels = {
"core-browser-loading-mechanics-priority-queues":
"Core Browser Loading Mechanics",
"resource-hint-implementation-preloading-strategies":
"Resource Hint Implementation",
"http2-http3-multiplexing-connection-optimization":
"HTTP/2 & HTTP/3 Multiplexing",
"understanding-browser-resource-priority-queues":
"Understanding Priority Queues",
"cache-interaction-stale-while-revalidate":
"Cache & Stale-While-Revalidate",
"network-waterfall-anatomy-timing-metrics":
"Network Waterfall Anatomy",
"render-blocking-resource-identification":
"Render-Blocking Resources",
"mastering-link-rel-preload-prefetch": "Mastering Preload & Prefetch",
"strategic-preconnect-dns-prefetch-usage":
"Strategic Preconnect & DNS-Prefetch",
"font-loading-optimization-fout-prevention":
"Font Loading & FOUT Prevention",
"dynamic-hint-injection-via-javascript":
"Dynamic Hint Injection via JS",
"http2-stream-prioritization-weighting":
"HTTP/2 Stream Prioritization",
"mitigating-head-of-line-blocking": "Mitigating Head-of-Line Blocking",
"connection-coalescing-domain-sharding":
"Connection Coalescing & Domain Sharding",
"cdn-edge-tuning-for-quic-http3": "CDN Edge Tuning for QUIC/HTTP3",
"how-browser-fetch-priority-affects-lcp":
"How Fetch Priority Affects LCP",
"cache-control-headers-vs-resource-hints":
"Cache-Control vs Resource Hints",
"decoding-chrome-devtools-network-waterfall":
"Decoding Chrome DevTools Waterfall",
"fixing-low-priority-critical-css-requests":
"Fixing Low-Priority Critical CSS",
"preloading-critical-above-the-fold-assets":
"Preloading Above-the-Fold Assets",
"when-to-use-preload-vs-prefetch-for-images":
"Preload vs Prefetch for Images",
"automating-preconnect-for-third-party-apis":
"Automating Preconnect for APIs",
"reducing-font-swap-with-font-display-swap":
"Reducing Font Swap (font-display)",
"fixing-http2-priority-inversion-issues":
"Fixing HTTP/2 Priority Inversion",
"does-http3-eliminate-head-of-line-blocking":
"Does HTTP/3 Eliminate HOL Blocking?",
"framework-specific-loading-strategies":
"Framework Loading Strategies",
"nextjs-resource-loading-optimization":
"Next.js Loading Optimization",
"fixing-nextjs-lcp-image-priority":
"Fixing Next.js LCP Image Priority",
"choosing-nextjs-script-strategy":
"Choosing a next/script Strategy",
"nuxt-resource-loading-optimization":
"Nuxt Loading Optimization",
"tuning-nuxt-link-prefetch-behavior":
"Tuning NuxtLink Prefetch",
"astro-islands-loading-optimization":
"Astro Islands Loading",
"sequencing-astro-client-directives":
"Sequencing Astro Client Directives",
"fetchpriority-attribute-priority-hints":
"fetchpriority & Priority Hints",
"fetchpriority-high-not-working-on-lcp-image":
"fetchpriority=high Not Working",
"deprioritizing-below-the-fold-images":
"Deprioritizing Below-Fold Images",
"third-party-resource-impact-mapping":
"Third-Party Impact Mapping",
"measuring-tag-manager-blocking-time":
"Measuring Tag Manager Blocking",
"replacing-third-party-embeds-with-facades":
"Replacing Embeds with Facades",
"stale-while-revalidate-vs-service-worker-cache":
"SWR vs Service Worker Cache",
"early-hints-103-implementation": "103 Early Hints",
"http2-server-push-vs-103-early-hints":
"Server Push vs 103 Early Hints",
"enabling-early-hints-on-cdn-and-origin":
"Enabling Early Hints on CDN & Origin",
"quic-0rtt-session-resumption-gotchas":
"QUIC 0-RTT Resumption Gotchas",
"rolling-out-alt-svc-headers-safely":
"Rolling Out Alt-Svc Safely",
"dismantling-domain-sharding-for-http3":
"Dismantling Domain Sharding",
"modulepreload-es-module-loading":
"modulepreload & ES Modules",
"fixing-dynamic-import-request-waterfalls":
"Fixing Dynamic Import Waterfalls",
"preload-vs-prefetch-vs-modulepreload-decision-matrix":
"Preload vs Prefetch vs modulepreload",
"speculation-rules-prefetch-prerender":
"Speculation Rules: Prefetch & Prerender",
"migrating-from-quicklink-to-speculation-rules":
"Migrating from Quicklink",
"fixing-preload-scanner-misses-in-spas":
"Preload Scanner Misses in SPAs",
"preventing-foit-with-font-loading-api":
"Preventing FOIT (Font Loading API)",
"script-loading-async-defer-execution-order":
"Script Loading: async & defer",
"fixing-async-script-race-conditions":
"Fixing async Script Race Conditions",
"deferring-third-party-scripts-without-breaking-analytics":
"Deferring Third-Party Scripts",
"lazy-loading-and-viewport-driven-fetching":
"Lazy Loading & Viewport Fetching",
"choosing-loading-lazy-vs-intersectionobserver":
'loading="lazy" vs IntersectionObserver',
"fixing-lazy-loaded-lcp-image-regressions":
"Fixing Lazy-Loaded LCP Regressions",
"using-content-visibility-to-skip-offscreen-rendering":
"Using content-visibility",
"chrome-vs-safari-vs-firefox-priority-differences":
"Chrome vs Safari vs Firefox",
"diagnosing-request-queueing-and-stalled-time":
"Request Queueing & Stalled Time",
"eliminating-render-blocking-css-with-media-queries":
"Render-Blocking CSS & Media Queries",
"auditing-render-blocking-with-lighthouse-treemap":
"Auditing with the Lighthouse Treemap",
"setting-a-third-party-request-budget":
"Third-Party Request Budget",
"preloading-video-and-media-streams":
"Preloading Video & Media",
"preloading-hls-and-dash-manifest-segments":
"Preloading HLS & DASH Segments",
"choosing-video-preload-metadata-vs-auto":
'video preload="metadata" vs "auto"',
"debugging-unused-preload-console-warnings":
"Debugging Unused Preload Warnings",
"preconnect-vs-dns-prefetch-decision-matrix":
"preconnect vs dns-prefetch",
"mapping-vite-chunk-graphs-to-modulepreload":
"Vite Chunk Graphs to modulepreload",
"injecting-hints-from-a-service-worker":
"Hints from a Service Worker",
"tuning-speculation-rules-eagerness-settings":
"Tuning Eagerness Settings",
"subsetting-and-preloading-variable-fonts":
"Subsetting Variable Fonts",
"measuring-protocol-performance-in-the-field":
"Measuring Protocol Performance",
"reading-server-timing-headers-for-protocol-stalls":
"Reading Server-Timing Headers",
"collecting-nexthopprotocol-with-resource-timing":
"Collecting nextHopProtocol",
"http2-priority-vs-http3-priority-header":
"Priority Trees vs Priority Header",
"tcp-vs-quic-loss-recovery-under-packet-loss":
"TCP vs QUIC Loss Recovery",
"verifying-connection-coalescing-with-devtools":
"Verifying Coalescing in DevTools",
"avoiding-early-hints-cache-poisoning":
"Avoiding Early Hints Cache Poisoning",
"sveltekit-resource-loading-optimization":
"SvelteKit Loading Optimization",
"tuning-sveltekit-data-preload-directives":
"Tuning SvelteKit Preload Directives",
"fixing-sveltekit-hydration-waterfalls":
"Fixing SvelteKit Hydration Waterfalls",
"optimizing-astro-view-transitions-prefetch":
"Astro View Transitions Prefetch",
"controlling-nuxt-payload-and-island-hydration":
"Nuxt Payload & Island Hydration",
};
for (const part of parts) {
current += "/" + part;
crumbs.push({ label: labels[part] || part, url: current + "/" });
}
return crumbs;
});
// Dirs
return {
dir: {
input: ".",
includes: "_includes",
output: "_site",
},
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
};
};