@timber-js/app 0.2.0-alpha.215 → 0.2.0-alpha.217

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/_chunks/als-registry-BZqHCtq-.js.map +1 -1
  2. package/dist/_chunks/{chains-CjK1Eu6a.js → chains-YKZ8WpIW.js} +2 -2
  3. package/dist/_chunks/{chains-CjK1Eu6a.js.map → chains-YKZ8WpIW.js.map} +1 -1
  4. package/dist/_chunks/{classify-GAdt6aiA.js → classify-2Yp3xJY1.js} +3 -3
  5. package/dist/_chunks/{classify-GAdt6aiA.js.map → classify-2Yp3xJY1.js.map} +1 -1
  6. package/dist/_chunks/{cli-check-DOzjlycg.js → cli-check-D2WtbNqo.js} +3 -3
  7. package/dist/_chunks/{cli-check-DOzjlycg.js.map → cli-check-D2WtbNqo.js.map} +1 -1
  8. package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js → cli-schema-sync-CySLKrO3.js} +2 -2
  9. package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js.map → cli-schema-sync-CySLKrO3.js.map} +1 -1
  10. package/dist/_chunks/{client-dep-entries-DEp8ZHce.js → client-dep-entries-BOkpKjj1.js} +2 -2
  11. package/dist/_chunks/{client-dep-entries-DEp8ZHce.js.map → client-dep-entries-BOkpKjj1.js.map} +1 -1
  12. package/dist/_chunks/{convention-lint-B3QEGJX7.js → convention-lint-ByKJ6aqD.js} +2 -2
  13. package/dist/_chunks/{convention-lint-B3QEGJX7.js.map → convention-lint-ByKJ6aqD.js.map} +1 -1
  14. package/dist/_chunks/{dev-server-_9L4KWC-.js → dev-server-B8zsT-ee.js} +4 -4
  15. package/dist/_chunks/{dev-server-_9L4KWC-.js.map → dev-server-B8zsT-ee.js.map} +1 -1
  16. package/dist/_chunks/{live-graph-Cd3YHvrH.js → live-graph-BhtrZpRd.js} +4 -4
  17. package/dist/_chunks/{live-graph-Cd3YHvrH.js.map → live-graph-BhtrZpRd.js.map} +1 -1
  18. package/dist/_chunks/{metadata-routes-DSDjM_hJ.js → metadata-routes-B3XJNyIH.js} +1 -2
  19. package/dist/_chunks/metadata-routes-B3XJNyIH.js.map +1 -0
  20. package/dist/_chunks/{poison-scan-BnJjBOkn.js → poison-scan-C4FgMxFl.js} +2 -2
  21. package/dist/_chunks/{poison-scan-BnJjBOkn.js.map → poison-scan-C4FgMxFl.js.map} +1 -1
  22. package/dist/_chunks/{scanner-CKAT5gRx.js → scanner-Cb3fSjAC.js} +4 -4
  23. package/dist/_chunks/{scanner-CKAT5gRx.js.map → scanner-Cb3fSjAC.js.map} +1 -1
  24. package/dist/_chunks/{walkers-DwCXEyRu.js → walkers-Ber9bamD.js} +3 -3
  25. package/dist/_chunks/{walkers-DwCXEyRu.js.map → walkers-Ber9bamD.js.map} +1 -1
  26. package/dist/adapters/nitro-immutable-assets.d.ts +47 -0
  27. package/dist/adapters/nitro-immutable-assets.d.ts.map +1 -0
  28. package/dist/adapters/nitro-preview.d.ts +3 -2
  29. package/dist/adapters/nitro-preview.d.ts.map +1 -1
  30. package/dist/adapters/nitro.d.ts +16 -2
  31. package/dist/adapters/nitro.d.ts.map +1 -1
  32. package/dist/adapters/nitro.js +130 -10
  33. package/dist/adapters/nitro.js.map +1 -1
  34. package/dist/analyze/crawl-entry.js +3 -3
  35. package/dist/analyze/graph-command.js +2 -2
  36. package/dist/cli.js +3 -3
  37. package/dist/index.js +6 -6
  38. package/dist/routing/index.js +2 -2
  39. package/dist/server/als-registry.d.ts +2 -0
  40. package/dist/server/als-registry.d.ts.map +1 -1
  41. package/dist/server/internal.js +2 -2
  42. package/dist/server/internal.js.map +1 -1
  43. package/dist/server/metadata-collector.d.ts +2 -0
  44. package/dist/server/metadata-collector.d.ts.map +1 -1
  45. package/dist/server/metadata-route-links.d.ts +70 -0
  46. package/dist/server/metadata-route-links.d.ts.map +1 -0
  47. package/dist/server/metadata-routes.d.ts +0 -24
  48. package/dist/server/metadata-routes.d.ts.map +1 -1
  49. package/dist/server/route-element-builder.d.ts.map +1 -1
  50. package/dist/server/route-matcher.d.ts +7 -0
  51. package/dist/server/route-matcher.d.ts.map +1 -1
  52. package/docs/api/34-api-config.mdx +1 -1
  53. package/package.json +1 -1
  54. package/src/adapters/nitro-immutable-assets.ts +142 -0
  55. package/src/adapters/nitro-preview.ts +12 -3
  56. package/src/adapters/nitro.ts +31 -17
  57. package/src/server/als-registry.ts +2 -0
  58. package/src/server/metadata-collector.ts +15 -17
  59. package/src/server/metadata-route-links.ts +200 -0
  60. package/src/server/metadata-routes.ts +0 -106
  61. package/src/server/route-element-builder.ts +1 -0
  62. package/src/server/route-matcher.ts +2 -2
  63. package/dist/_chunks/metadata-routes-DSDjM_hJ.js.map +0 -1
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Auto-linking: turn the metadata route files in a page's segment chain into
3
+ * the <link>/<meta> tags its <head> carries, and decide precedence between
4
+ * those files and the metadata the app declares.
5
+ *
6
+ * Every link must name a file the metadata route matcher actually serves at
7
+ * that URL, so the OG winner is chosen by asking the matcher rather than by
8
+ * modelling its precedence here.
9
+ *
10
+ * See design/16-metadata.md §"Auto-Linking".
11
+ */
12
+
13
+ import { randomUUID } from 'node:crypto';
14
+ import type { HeadElement } from './metadata.ts';
15
+ import type { Metadata } from './types.ts';
16
+ import { matchMetadataRoute, type ManifestSegmentNode } from './route-matcher.ts';
17
+ import { extractUrlParts } from './chain-url-parts.ts';
18
+ import {
19
+ METADATA_ROUTE_CONVENTIONS,
20
+ getMetadataRouteAutoLink,
21
+ resolveServePathForFile,
22
+ type MetadataRouteType,
23
+ } from './metadata-routes.ts';
24
+
25
+ // In dev mode, use a per-startup nonce for metadata route cache busting
26
+ // instead of per-file content hashes (avoids rehashing on every request).
27
+ let _devNonce: string | undefined;
28
+ function getDevNonce(): string {
29
+ _devNonce ??= randomUUID().slice(0, 8);
30
+ return _devNonce;
31
+ }
32
+
33
+ /**
34
+ * Segment index whose metadata export supplied the resolved `openGraph.images`
35
+ * and `twitter.images`, or -1 when none did. A file-based `opengraph-image`
36
+ * replaces declared images only from a deeper segment.
37
+ */
38
+ export interface DeclaredImageOwners {
39
+ openGraph: number;
40
+ twitter: number;
41
+ }
42
+
43
+ /**
44
+ * Find which segment's export supplied the resolved `openGraph.images` and
45
+ * `twitter.images`: the deepest entry whose images are the resolved value.
46
+ * Read off the merge result rather than re-deriving `resolveMetadata`'s merge
47
+ * rule, so the two cannot drift.
48
+ */
49
+ export function findDeclaredImageOwners(
50
+ entries: { metadata: Metadata; segmentIndex: number }[],
51
+ resolved: Metadata
52
+ ): DeclaredImageOwners {
53
+ const owners: DeclaredImageOwners = { openGraph: -1, twitter: -1 };
54
+ const ogImages = resolved.openGraph?.images;
55
+ const twitterImages = resolved.twitter?.images;
56
+ for (const { metadata, segmentIndex } of entries) {
57
+ if (ogImages && metadata.openGraph?.images === ogImages) owners.openGraph = segmentIndex;
58
+ if (twitterImages && metadata.twitter?.images === twitterImages) owners.twitter = segmentIndex;
59
+ }
60
+ return owners;
61
+ }
62
+
63
+ /** Auto-linked head elements, and the declared metadata they leave in force. */
64
+ export interface MetadataRouteLinks {
65
+ /** `resolvedMetadata` minus any declared images a deeper file replaced. */
66
+ metadata: Metadata;
67
+ elements: HeadElement[];
68
+ }
69
+
70
+ /**
71
+ * Link metadata route files in the segment chain into the page's head.
72
+ *
73
+ * Walks each segment's metadataRoutes, resolves serve paths and URLs, and
74
+ * emits HeadElement descriptors for <link> and <meta> tags that React Float
75
+ * hoists into <head>.
76
+ *
77
+ * A metadata file is served under the URL of the segment that owns it, not
78
+ * under every descendant URL: a root `app/icon.tsx` rendered on `/map` links
79
+ * `/icon.png`, and `app/posts/[id]/opengraph-image.tsx` on `/posts/42/comments`
80
+ * links `/posts/42/opengraph-image.png`. The owner's prefix is the URL parts
81
+ * the chain has consumed through that segment (`extractUrlParts`, the same
82
+ * walk slot matching uses), filled with the request's raw param values — the
83
+ * parts the metadata route matcher walks back to the same owner.
84
+ *
85
+ * Segments at or below an intercepting segment are skipped: the metadata
86
+ * matcher only walks the canonical tree, so nothing serves their files.
87
+ *
88
+ * Precedence, so no tag is ever emitted twice:
89
+ * - Icon and apple-icon files link from every segment, root to leaf, unless
90
+ * the metadata declares `icons.icon` / `icons.apple`. A declared manifest
91
+ * likewise replaces `app/manifest.*`.
92
+ * - Only the deepest served `opengraph-image` links. It replaces declared
93
+ * `openGraph.images` / `twitter.images` from a shallower segment (those are
94
+ * dropped from the returned metadata) and yields to images declared at its
95
+ * own segment or deeper.
96
+ *
97
+ * See design/16-metadata.md §"Auto-Linking"
98
+ */
99
+ export function linkMetadataRoutes(
100
+ segments: ManifestSegmentNode[],
101
+ resolvedMetadata: Metadata,
102
+ declaredImages: DeclaredImageOwners,
103
+ requestUrl: URL,
104
+ rawSegmentParams: Record<string, string | string[]>,
105
+ metadataRouteHashes?: Record<string, string>
106
+ ): MetadataRouteLinks {
107
+ const elements: HeadElement[] = [];
108
+ // In dev mode, use the request origin so OG URLs resolve to localhost.
109
+ // In production, use metadataBase (the canonical domain).
110
+ const ogBase =
111
+ process.env.NODE_ENV !== 'production'
112
+ ? new URL(requestUrl.origin)
113
+ : resolvedMetadata.metadataBase;
114
+
115
+ const interceptingIndex = segments.findIndex((s) => s.segmentType === 'intercepting');
116
+ const servedDepth = interceptingIndex === -1 ? segments.length : interceptingIndex;
117
+
118
+ // The canonical (decoded) URL parts each served segment owns.
119
+ const ownerParts = segments
120
+ .slice(0, servedDepth)
121
+ .map((_, si) => extractUrlParts(segments.slice(0, si + 1), rawSegmentParams));
122
+
123
+ // The OG winner is the deepest segment whose link the metadata matcher
124
+ // resolves back to that segment's own file. Several segments can share one
125
+ // URL — a group or a zero-length [[...slug]] adds no part, and sibling
126
+ // groups off the chain own the same root URL — and only one file is served
127
+ // there, so asking the matcher is the one way the link and its cache-bust
128
+ // hash cannot name a different image than the URL returns.
129
+ let ogFileIndex = -1;
130
+ for (let si = servedDepth - 1; si >= 0 && ogFileIndex === -1; si--) {
131
+ for (const [baseName, file] of Object.entries(segments[si].metadataRoutes ?? {})) {
132
+ if (METADATA_ROUTE_CONVENTIONS[baseName]?.type !== 'opengraph-image') continue;
133
+ const path = ['', ...ownerParts[si], resolveServePathForFile(baseName, file.filePath)].join(
134
+ '/'
135
+ );
136
+ if (matchMetadataRoute(segments[0], path)?.file === file) ogFileIndex = si;
137
+ }
138
+ }
139
+ const linkOgImage = ogFileIndex > declaredImages.openGraph;
140
+ const linkTwitterImage = linkOgImage && ogFileIndex > declaredImages.twitter;
141
+ const declaredTypes = new Set<MetadataRouteType>();
142
+ if (resolvedMetadata.icons?.icon) declaredTypes.add('icon');
143
+ if (resolvedMetadata.icons?.apple) declaredTypes.add('apple-icon');
144
+ if (resolvedMetadata.manifest) declaredTypes.add('manifest');
145
+
146
+ for (let si = 0; si < servedDepth; si++) {
147
+ const segment = segments[si];
148
+ if (!segment.metadataRoutes) continue;
149
+ // Encode each part so the href canonicalizes back to the pathname the
150
+ // matcher resolves to this owner.
151
+ const segmentPrefix = ownerParts[si].map((part) => `/${encodeURIComponent(part)}`).join('');
152
+ for (const baseName of Object.keys(segment.metadataRoutes)) {
153
+ const convention = METADATA_ROUTE_CONVENTIONS[baseName];
154
+ if (!convention) continue;
155
+ if (!convention.nestable && segment.urlPath !== '/') continue;
156
+ if (declaredTypes.has(convention.type)) continue;
157
+ if (convention.type === 'opengraph-image' && (!linkOgImage || si !== ogFileIndex)) {
158
+ continue;
159
+ }
160
+ const metaFile = segment.metadataRoutes[baseName];
161
+ const fileServePath = metaFile?.filePath
162
+ ? resolveServePathForFile(baseName, metaFile.filePath)
163
+ : convention.serveExtension
164
+ ? `${convention.servePath}.${convention.serveExtension}`
165
+ : convention.servePath;
166
+ let href = `${segmentPrefix}/${fileServePath}`;
167
+ if (convention.type === 'opengraph-image') {
168
+ const fileHash = metaFile?.filePath ? metadataRouteHashes?.[metaFile.filePath] : undefined;
169
+ const cacheBust = fileHash ?? getDevNonce();
170
+ href = `${href}?${cacheBust}`;
171
+ }
172
+ if (ogBase && convention.type === 'opengraph-image') {
173
+ href = new URL(href, ogBase).toString();
174
+ }
175
+ for (const autoLink of getMetadataRouteAutoLink(convention.type, href)) {
176
+ if (autoLink.tag === 'link') {
177
+ const attrs: Record<string, string> = { rel: autoLink.rel, href: autoLink.href };
178
+ if (autoLink.type) attrs.type = autoLink.type;
179
+ elements.push({ tag: 'link', attrs });
180
+ } else {
181
+ if (autoLink.name === 'twitter:image' && !linkTwitterImage) continue;
182
+ const attrs: Record<string, string> = { content: autoLink.content };
183
+ if (autoLink.property) attrs.property = autoLink.property;
184
+ if (autoLink.name) attrs.name = autoLink.name;
185
+ elements.push({ tag: 'meta', attrs });
186
+ }
187
+ }
188
+ }
189
+ }
190
+
191
+ // The linked file replaces images declared by a shallower segment.
192
+ const metadata = { ...resolvedMetadata };
193
+ if (linkOgImage && metadata.openGraph?.images) {
194
+ metadata.openGraph = { ...metadata.openGraph, images: undefined };
195
+ }
196
+ if (linkTwitterImage && metadata.twitter?.images) {
197
+ metadata.twitter = { ...metadata.twitter, images: undefined };
198
+ }
199
+ return { metadata, elements };
200
+ }
@@ -10,11 +10,9 @@
10
10
  * See design/16-metadata.md §"Metadata Routes"
11
11
  */
12
12
 
13
- import { randomUUID } from 'node:crypto';
14
13
  import type { HeadElement } from './metadata.ts';
15
14
  import type { Metadata } from './types.ts';
16
15
  import type { ManifestSegmentNode } from './route-matcher.ts';
17
- import { extractUrlParts } from './chain-url-parts.ts';
18
16
 
19
17
  // ─── Types ───────────────────────────────────────────────────────────────────
20
18
 
@@ -340,107 +338,3 @@ export function getMetadataRouteAutoLink(type: MetadataRouteType, href: string):
340
338
  return [];
341
339
  }
342
340
  }
343
-
344
- // ─── Auto-Linking ──────────────────────────────────────────────────────────
345
-
346
- // In dev mode, use a per-startup nonce for metadata route cache busting
347
- // instead of per-file content hashes (avoids rehashing on every request).
348
- let _devNonce: string | undefined;
349
- function getDevNonce(): string {
350
- _devNonce ??= randomUUID().slice(0, 8);
351
- return _devNonce;
352
- }
353
-
354
- /**
355
- * Collect auto-linked head elements from metadata route files in the segment chain.
356
- *
357
- * Walks each segment's metadataRoutes, resolves serve paths and URLs, and
358
- * emits HeadElement descriptors for <link> and <meta> tags that React Float
359
- * hoists into <head>.
360
- *
361
- * A metadata file is served under the URL of the segment that owns it, not
362
- * under every descendant URL: a root `app/icon.tsx` rendered on `/map` links
363
- * `/icon.png`, and `app/posts/[id]/opengraph-image.tsx` on `/posts/42/comments`
364
- * links `/posts/42/opengraph-image.png`. The owner's prefix is the URL parts
365
- * the chain has consumed through that segment (`extractUrlParts`, the same
366
- * walk slot matching uses), filled with the request's raw param values — the
367
- * parts the metadata route matcher walks back to the same owner.
368
- *
369
- * Segments at or below an intercepting segment are skipped: the metadata
370
- * matcher only walks the canonical tree, so nothing serves their files.
371
- *
372
- * See design/16-metadata.md §"Auto-Linking"
373
- */
374
- export function collectMetadataRouteHeadElements(
375
- segments: ManifestSegmentNode[],
376
- firstDeniedIndex: number,
377
- resolvedMetadata: Metadata,
378
- requestUrl: URL,
379
- rawSegmentParams: Record<string, string | string[]>,
380
- metadataRouteHashes?: Record<string, string>
381
- ): HeadElement[] {
382
- const elements: HeadElement[] = [];
383
- const hasUserOgImage = Boolean(resolvedMetadata.openGraph?.images);
384
- const hasUserTwitterImage = Boolean(resolvedMetadata.twitter?.images);
385
- // In dev mode, use the request origin so OG URLs resolve to localhost.
386
- // In production, use metadataBase (the canonical domain).
387
- const ogBase =
388
- process.env.NODE_ENV !== 'production'
389
- ? new URL(requestUrl.origin)
390
- : resolvedMetadata.metadataBase;
391
-
392
- const interceptingIndex = segments.findIndex((s) => s.segmentType === 'intercepting');
393
- const servedDepth = interceptingIndex === -1 ? segments.length : interceptingIndex;
394
-
395
- for (let si = 0; si < servedDepth; si++) {
396
- const segment = segments[si];
397
- if (!segment.metadataRoutes) continue;
398
- if (si >= firstDeniedIndex) continue;
399
- // Params are canonical (decoded) values; encode each part so the href
400
- // canonicalizes back to the pathname the matcher resolves to this owner.
401
- const segmentPrefix = extractUrlParts(segments.slice(0, si + 1), rawSegmentParams)
402
- .map((part) => `/${encodeURIComponent(part)}`)
403
- .join('');
404
- for (const baseName of Object.keys(segment.metadataRoutes)) {
405
- const convention = METADATA_ROUTE_CONVENTIONS[baseName];
406
- if (!convention) continue;
407
- if (!convention.nestable && segment.urlPath !== '/') continue;
408
- if (convention.type === 'opengraph-image' && hasUserOgImage) continue;
409
- const metaFile = segment.metadataRoutes[baseName];
410
- const fileServePath = metaFile?.filePath
411
- ? resolveServePathForFile(baseName, metaFile.filePath)
412
- : convention.serveExtension
413
- ? `${convention.servePath}.${convention.serveExtension}`
414
- : convention.servePath;
415
- let href = `${segmentPrefix}/${fileServePath}`;
416
- if (convention.type === 'opengraph-image') {
417
- const fileHash = metaFile?.filePath ? metadataRouteHashes?.[metaFile.filePath] : undefined;
418
- const cacheBust = fileHash ?? getDevNonce();
419
- href = `${href}?${cacheBust}`;
420
- }
421
- if (ogBase && convention.type === 'opengraph-image') {
422
- href = new URL(href, ogBase).toString();
423
- }
424
- for (const autoLink of getMetadataRouteAutoLink(convention.type, href)) {
425
- if (
426
- hasUserTwitterImage &&
427
- autoLink.tag === 'meta' &&
428
- 'name' in autoLink &&
429
- autoLink.name === 'twitter:image'
430
- )
431
- continue;
432
- if (autoLink.tag === 'link') {
433
- const attrs: Record<string, string> = { rel: autoLink.rel, href: autoLink.href };
434
- if (autoLink.type) attrs.type = autoLink.type;
435
- elements.push({ tag: 'link', attrs });
436
- } else {
437
- const attrs: Record<string, string> = { content: autoLink.content };
438
- if (autoLink.property) attrs.property = autoLink.property;
439
- if (autoLink.name) attrs.name = autoLink.name;
440
- elements.push({ tag: 'meta', attrs });
441
- }
442
- }
443
- }
444
- }
445
- return elements;
446
- }
@@ -148,6 +148,7 @@ function wrapMetadataCollectors(
148
148
  metadataExport: meta.metadataExport,
149
149
  segmentName: meta.segmentName,
150
150
  isPage: meta.isPage,
151
+ segmentIndex: meta.segmentIndex,
151
152
  children: element,
152
153
  });
153
154
  }
@@ -186,7 +186,7 @@ for (const [baseName, convention] of Object.entries(METADATA_ROUTE_CONVENTIONS))
186
186
  export function createMetadataRouteMatcher(
187
187
  manifest: ManifestRoot
188
188
  ): (pathname: string) => MetadataRouteMatch | null {
189
- return (pathname: string) => matchMetadataPathname(manifest.root, pathname);
189
+ return (pathname: string) => matchMetadataRoute(manifest.root, pathname);
190
190
  }
191
191
 
192
192
  /**
@@ -195,7 +195,7 @@ export function createMetadataRouteMatcher(
195
195
  * Checks if the last URL part is a known metadata route serve path,
196
196
  * then walks the tree to find the segment that owns the route.
197
197
  */
198
- function matchMetadataPathname(
198
+ export function matchMetadataRoute(
199
199
  root: ManifestSegmentNode,
200
200
  pathname: string
201
201
  ): MetadataRouteMatch | null {
@@ -1 +0,0 @@
1
- {"version":3,"file":"metadata-routes-DSDjM_hJ.js","names":[],"sources":["../../src/server/metadata-routes.ts"],"sourcesContent":["/**\n * Metadata route classification for timber.js.\n *\n * Metadata routes are file-based endpoints that generate well-known URLs for\n * crawlers and browsers (sitemap.xml, robots.txt, OG images, etc.).\n *\n * These routes run through proxy.ts but NOT through middleware.ts or access.ts —\n * they are public endpoints by nature.\n *\n * See design/16-metadata.md §\"Metadata Routes\"\n */\n\nimport { randomUUID } from 'node:crypto';\nimport type { HeadElement } from './metadata.ts';\nimport type { Metadata } from './types.ts';\nimport type { ManifestSegmentNode } from './route-matcher.ts';\nimport { extractUrlParts } from './chain-url-parts.ts';\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Classification of a metadata route file. */\nexport interface MetadataRouteInfo {\n /** The metadata route type. */\n type: MetadataRouteType;\n /** The content type to serve this route with. */\n contentType: string;\n /** Whether this route can appear in nested segments (not just app root). */\n nestable: boolean;\n}\n\nexport type MetadataRouteType =\n | 'sitemap'\n | 'robots'\n | 'manifest'\n | 'favicon'\n | 'icon'\n | 'opengraph-image'\n | 'apple-icon';\n\n// ─── Convention Table ────────────────────────────────────────────────────────\n\n/**\n * All recognized metadata route file conventions.\n *\n * Each entry maps a base file name (without extension) to its route info.\n * The extensions determine whether the file is static or dynamic.\n *\n * Static extensions: .xml, .txt, .json, .png, .jpg, .ico, .svg\n * Dynamic extensions: .ts, .tsx\n */\nexport const METADATA_ROUTE_CONVENTIONS: Record<\n string,\n {\n type: MetadataRouteType;\n contentType: string;\n nestable: boolean;\n staticExtensions: string[];\n dynamicExtensions: string[];\n /**\n * The URL path basename this file serves at (relative to segment).\n * For image routes, the full serve path includes an extension via\n * `resolveServePathForFile()`.\n */\n servePath: string;\n /**\n * When set, image routes append `.{serveExtension}` to the serve path.\n * Dynamic handlers (`.ts`/`.tsx`) use this as the default. Static files\n * use their own extension instead. Non-image routes leave this undefined.\n */\n serveExtension?: string;\n }\n> = {\n 'sitemap': {\n type: 'sitemap',\n contentType: 'application/xml',\n nestable: true,\n staticExtensions: ['xml'],\n dynamicExtensions: ['ts'],\n servePath: 'sitemap.xml',\n },\n 'robots': {\n type: 'robots',\n contentType: 'text/plain',\n nestable: false,\n staticExtensions: ['txt'],\n dynamicExtensions: ['ts'],\n servePath: 'robots.txt',\n },\n 'manifest': {\n type: 'manifest',\n contentType: 'application/manifest+json',\n nestable: false,\n staticExtensions: ['json'],\n dynamicExtensions: ['ts'],\n servePath: 'manifest.webmanifest',\n },\n 'favicon': {\n type: 'favicon',\n contentType: 'image/x-icon',\n nestable: false,\n staticExtensions: ['ico'],\n dynamicExtensions: ['ts', 'tsx'],\n servePath: 'favicon.ico',\n },\n 'icon': {\n type: 'icon',\n contentType: 'image/*',\n nestable: true,\n staticExtensions: ['png', 'jpg', 'svg'],\n dynamicExtensions: ['ts', 'tsx'],\n servePath: 'icon',\n serveExtension: 'png',\n },\n 'opengraph-image': {\n type: 'opengraph-image',\n contentType: 'image/*',\n nestable: true,\n staticExtensions: ['png', 'jpg'],\n dynamicExtensions: ['ts', 'tsx'],\n servePath: 'opengraph-image',\n serveExtension: 'png',\n },\n\n 'apple-icon': {\n type: 'apple-icon',\n contentType: 'image/*',\n nestable: true,\n staticExtensions: ['png'],\n dynamicExtensions: ['ts', 'tsx'],\n servePath: 'apple-icon',\n serveExtension: 'png',\n },\n};\n\n// ─── MIME Type Resolution ─────────────────────────────────────────────────────\n\n/**\n * Map of file extensions to MIME types for static metadata route files.\n * Used to resolve the generic `image/*` content type for static image files.\n */\nconst EXTENSION_MIME_TYPES: Record<string, string> = {\n xml: 'application/xml',\n txt: 'text/plain',\n json: 'application/json',\n ico: 'image/x-icon',\n png: 'image/png',\n jpg: 'image/jpeg',\n jpeg: 'image/jpeg',\n svg: 'image/svg+xml',\n webp: 'image/webp',\n};\n\n/**\n * Resolve the concrete MIME type for a static metadata route file.\n *\n * For generic content types like `image/*`, this resolves to the actual\n * MIME type based on the file extension (e.g. `image/png` for `.png`).\n *\n * @param conventionContentType - The content type from the convention table (may be generic like `image/*`)\n * @param extension - The file extension without leading dot (e.g. \"png\", \"xml\")\n * @returns The resolved MIME type\n */\nexport function resolveStaticContentType(conventionContentType: string, extension: string): string {\n if (conventionContentType.includes('*')) {\n return EXTENSION_MIME_TYPES[extension] ?? 'application/octet-stream';\n }\n return conventionContentType;\n}\n\n/**\n * Check if a file extension represents a static (non-code) metadata route file.\n *\n * @param baseName - The base file name without extension (e.g. \"sitemap\", \"icon\")\n * @param extension - The file extension without leading dot (e.g. \"xml\", \"png\", \"ts\")\n * @returns true if this is a static file, false if dynamic or unrecognized\n */\nexport function isStaticMetadataExtension(baseName: string, extension: string): boolean {\n const convention = METADATA_ROUTE_CONVENTIONS[baseName];\n if (!convention) return false;\n return convention.staticExtensions.includes(extension);\n}\n\n/**\n * Check if a file extension represents a dynamic (code) metadata route file.\n *\n * @param baseName - The base file name without extension (e.g. \"sitemap\", \"icon\")\n * @param extension - The file extension without leading dot (e.g. \"ts\", \"tsx\")\n * @returns true if this is a dynamic file, false if static or unrecognized\n */\nexport function isDynamicMetadataExtension(baseName: string, extension: string): boolean {\n const convention = METADATA_ROUTE_CONVENTIONS[baseName];\n if (!convention) return false;\n return convention.dynamicExtensions.includes(extension);\n}\n\n// ─── Classification ──────────────────────────────────────────────────────────\n\n/**\n * Classify a file name as a metadata route, or return null if it's not one.\n *\n * @param fileName - The full file name including extension (e.g. \"sitemap.xml\", \"icon.tsx\")\n * @returns Classification info, or null if not a metadata route\n */\nexport function classifyMetadataRoute(fileName: string): MetadataRouteInfo | null {\n const dotIndex = fileName.lastIndexOf('.');\n if (dotIndex === -1) return null;\n\n const baseName = fileName.slice(0, dotIndex);\n const ext = fileName.slice(dotIndex + 1);\n\n const convention = METADATA_ROUTE_CONVENTIONS[baseName];\n if (!convention) return null;\n\n const isStatic = convention.staticExtensions.includes(ext);\n const isDynamic = convention.dynamicExtensions.includes(ext);\n\n if (!isStatic && !isDynamic) return null;\n\n return {\n type: convention.type,\n contentType: convention.contentType,\n nestable: convention.nestable,\n };\n}\n\n/**\n * Resolve the serve path for a metadata route file.\n *\n * For image routes (icon, opengraph-image, apple-icon), the serve path includes\n * a file extension so CDNs cache correctly:\n * - Dynamic handlers (.ts/.tsx) use the convention's `serveExtension` (default: .png)\n * - Static files use their own extension (e.g., icon.svg → icon.svg)\n *\n * Non-image routes return the convention's `servePath` as-is (already includes\n * extension: sitemap.xml, robots.txt, etc.).\n */\nexport function resolveServePathForFile(baseName: string, filePath: string): string {\n const convention = METADATA_ROUTE_CONVENTIONS[baseName];\n if (!convention) return baseName;\n\n if (!convention.serveExtension) return convention.servePath;\n\n const ext = filePath.slice(filePath.lastIndexOf('.') + 1);\n if (convention.staticExtensions.includes(ext)) {\n return `${convention.servePath}.${ext}`;\n }\n return `${convention.servePath}.${convention.serveExtension}`;\n}\n\n/**\n * Get the default serve path for a metadata route type (using default extension\n * for image routes). Used for auto-link generation when only the type is known.\n */\nexport function getMetadataRouteServePath(type: MetadataRouteType): string {\n for (const convention of Object.values(METADATA_ROUTE_CONVENTIONS)) {\n if (convention.type === type) {\n if (convention.serveExtension) {\n return `${convention.servePath}.${convention.serveExtension}`;\n }\n return convention.servePath;\n }\n }\n throw new Error(`[timber] Unknown metadata route type: ${type}`);\n}\n\n/**\n * All possible serve path segments for metadata routes (includes extension\n * variants for image routes).\n */\nconst METADATA_SERVE_PATHS = new Set<string>();\nfor (const convention of Object.values(METADATA_ROUTE_CONVENTIONS)) {\n if (convention.serveExtension) {\n for (const ext of [...convention.staticExtensions, convention.serveExtension]) {\n METADATA_SERVE_PATHS.add(`${convention.servePath}.${ext}`);\n }\n } else {\n METADATA_SERVE_PATHS.add(convention.servePath);\n }\n}\n\nexport function isMetadataRouteServePath(pathname: string): boolean {\n let lastSegment = pathname.slice(pathname.lastIndexOf('/') + 1);\n const qIdx = lastSegment.indexOf('?');\n let query = '';\n if (qIdx !== -1) {\n query = lastSegment.slice(qIdx + 1);\n lastSegment = lastSegment.slice(0, qIdx);\n }\n if (!METADATA_SERVE_PATHS.has(lastSegment)) return false;\n // Vite module requests (e.g., /src/icon.svg?import) use special query params.\n // These are source assets, not metadata routes.\n if (/(?:^|&)(?:import|url|raw|worker|inline)(?:&|$)/.test(query)) return false;\n return true;\n}\n\n/** A <link> auto-link tag. */\nexport interface AutoLinkLink {\n tag: 'link';\n rel: string;\n href: string;\n type?: string;\n}\n\n/** A <meta> auto-link tag. */\nexport interface AutoLinkMeta {\n tag: 'meta';\n property?: string;\n name?: string;\n content: string;\n}\n\nexport type AutoLinkTag = AutoLinkLink | AutoLinkMeta;\n\n/**\n * Get the auto-link tags to inject into <head> for metadata route files\n * discovered in a segment.\n *\n * Returns link tags for icon/apple-icon/manifest, and meta tags for\n * opengraph-image (emits both og:image and twitter:image). Returns null\n * for types that don't auto-link (favicon, sitemap, robots).\n *\n * @param type - The metadata route type\n * @param href - The resolved URL path to the metadata route\n * @returns Tag descriptor(s) for the <head>, or null if no auto-link\n */\nexport function getMetadataRouteAutoLink(type: MetadataRouteType, href: string): AutoLinkTag[] {\n switch (type) {\n case 'icon':\n return [{ tag: 'link', rel: 'icon', href }];\n case 'apple-icon':\n return [{ tag: 'link', rel: 'apple-touch-icon', href }];\n case 'manifest':\n return [{ tag: 'link', rel: 'manifest', href }];\n case 'opengraph-image':\n return [\n { tag: 'meta', property: 'og:image', content: href },\n { tag: 'meta', name: 'twitter:image', content: href },\n ];\n default:\n return [];\n }\n}\n\n// ─── Auto-Linking ──────────────────────────────────────────────────────────\n\n// In dev mode, use a per-startup nonce for metadata route cache busting\n// instead of per-file content hashes (avoids rehashing on every request).\nlet _devNonce: string | undefined;\nfunction getDevNonce(): string {\n _devNonce ??= randomUUID().slice(0, 8);\n return _devNonce;\n}\n\n/**\n * Collect auto-linked head elements from metadata route files in the segment chain.\n *\n * Walks each segment's metadataRoutes, resolves serve paths and URLs, and\n * emits HeadElement descriptors for <link> and <meta> tags that React Float\n * hoists into <head>.\n *\n * A metadata file is served under the URL of the segment that owns it, not\n * under every descendant URL: a root `app/icon.tsx` rendered on `/map` links\n * `/icon.png`, and `app/posts/[id]/opengraph-image.tsx` on `/posts/42/comments`\n * links `/posts/42/opengraph-image.png`. The owner's prefix is the URL parts\n * the chain has consumed through that segment (`extractUrlParts`, the same\n * walk slot matching uses), filled with the request's raw param values — the\n * parts the metadata route matcher walks back to the same owner.\n *\n * Segments at or below an intercepting segment are skipped: the metadata\n * matcher only walks the canonical tree, so nothing serves their files.\n *\n * See design/16-metadata.md §\"Auto-Linking\"\n */\nexport function collectMetadataRouteHeadElements(\n segments: ManifestSegmentNode[],\n firstDeniedIndex: number,\n resolvedMetadata: Metadata,\n requestUrl: URL,\n rawSegmentParams: Record<string, string | string[]>,\n metadataRouteHashes?: Record<string, string>\n): HeadElement[] {\n const elements: HeadElement[] = [];\n const hasUserOgImage = Boolean(resolvedMetadata.openGraph?.images);\n const hasUserTwitterImage = Boolean(resolvedMetadata.twitter?.images);\n // In dev mode, use the request origin so OG URLs resolve to localhost.\n // In production, use metadataBase (the canonical domain).\n const ogBase =\n process.env.NODE_ENV !== 'production'\n ? new URL(requestUrl.origin)\n : resolvedMetadata.metadataBase;\n\n const interceptingIndex = segments.findIndex((s) => s.segmentType === 'intercepting');\n const servedDepth = interceptingIndex === -1 ? segments.length : interceptingIndex;\n\n for (let si = 0; si < servedDepth; si++) {\n const segment = segments[si];\n if (!segment.metadataRoutes) continue;\n if (si >= firstDeniedIndex) continue;\n // Params are canonical (decoded) values; encode each part so the href\n // canonicalizes back to the pathname the matcher resolves to this owner.\n const segmentPrefix = extractUrlParts(segments.slice(0, si + 1), rawSegmentParams)\n .map((part) => `/${encodeURIComponent(part)}`)\n .join('');\n for (const baseName of Object.keys(segment.metadataRoutes)) {\n const convention = METADATA_ROUTE_CONVENTIONS[baseName];\n if (!convention) continue;\n if (!convention.nestable && segment.urlPath !== '/') continue;\n if (convention.type === 'opengraph-image' && hasUserOgImage) continue;\n const metaFile = segment.metadataRoutes[baseName];\n const fileServePath = metaFile?.filePath\n ? resolveServePathForFile(baseName, metaFile.filePath)\n : convention.serveExtension\n ? `${convention.servePath}.${convention.serveExtension}`\n : convention.servePath;\n let href = `${segmentPrefix}/${fileServePath}`;\n if (convention.type === 'opengraph-image') {\n const fileHash = metaFile?.filePath ? metadataRouteHashes?.[metaFile.filePath] : undefined;\n const cacheBust = fileHash ?? getDevNonce();\n href = `${href}?${cacheBust}`;\n }\n if (ogBase && convention.type === 'opengraph-image') {\n href = new URL(href, ogBase).toString();\n }\n for (const autoLink of getMetadataRouteAutoLink(convention.type, href)) {\n if (\n hasUserTwitterImage &&\n autoLink.tag === 'meta' &&\n 'name' in autoLink &&\n autoLink.name === 'twitter:image'\n )\n continue;\n if (autoLink.tag === 'link') {\n const attrs: Record<string, string> = { rel: autoLink.rel, href: autoLink.href };\n if (autoLink.type) attrs.type = autoLink.type;\n elements.push({ tag: 'link', attrs });\n } else {\n const attrs: Record<string, string> = { content: autoLink.content };\n if (autoLink.property) attrs.property = autoLink.property;\n if (autoLink.name) attrs.name = autoLink.name;\n elements.push({ tag: 'meta', attrs });\n }\n }\n }\n }\n return elements;\n}\n"],"mappings":";;;;;;;;;;;AA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