@timber-js/app 0.2.0-alpha.215 → 0.2.0-alpha.216
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.
- package/dist/_chunks/als-registry-BZqHCtq-.js.map +1 -1
- package/dist/_chunks/{chains-CjK1Eu6a.js → chains-YKZ8WpIW.js} +2 -2
- package/dist/_chunks/{chains-CjK1Eu6a.js.map → chains-YKZ8WpIW.js.map} +1 -1
- package/dist/_chunks/{classify-GAdt6aiA.js → classify-2Yp3xJY1.js} +3 -3
- package/dist/_chunks/{classify-GAdt6aiA.js.map → classify-2Yp3xJY1.js.map} +1 -1
- package/dist/_chunks/{cli-check-DOzjlycg.js → cli-check-D2WtbNqo.js} +3 -3
- package/dist/_chunks/{cli-check-DOzjlycg.js.map → cli-check-D2WtbNqo.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js → cli-schema-sync-CySLKrO3.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js.map → cli-schema-sync-CySLKrO3.js.map} +1 -1
- package/dist/_chunks/{client-dep-entries-DEp8ZHce.js → client-dep-entries-BOkpKjj1.js} +2 -2
- package/dist/_chunks/{client-dep-entries-DEp8ZHce.js.map → client-dep-entries-BOkpKjj1.js.map} +1 -1
- package/dist/_chunks/{convention-lint-B3QEGJX7.js → convention-lint-ByKJ6aqD.js} +2 -2
- package/dist/_chunks/{convention-lint-B3QEGJX7.js.map → convention-lint-ByKJ6aqD.js.map} +1 -1
- package/dist/_chunks/{dev-server-_9L4KWC-.js → dev-server-B8zsT-ee.js} +4 -4
- package/dist/_chunks/{dev-server-_9L4KWC-.js.map → dev-server-B8zsT-ee.js.map} +1 -1
- package/dist/_chunks/{live-graph-Cd3YHvrH.js → live-graph-BhtrZpRd.js} +4 -4
- package/dist/_chunks/{live-graph-Cd3YHvrH.js.map → live-graph-BhtrZpRd.js.map} +1 -1
- package/dist/_chunks/{metadata-routes-DSDjM_hJ.js → metadata-routes-B3XJNyIH.js} +1 -2
- package/dist/_chunks/metadata-routes-B3XJNyIH.js.map +1 -0
- package/dist/_chunks/{poison-scan-BnJjBOkn.js → poison-scan-C4FgMxFl.js} +2 -2
- package/dist/_chunks/{poison-scan-BnJjBOkn.js.map → poison-scan-C4FgMxFl.js.map} +1 -1
- package/dist/_chunks/{scanner-CKAT5gRx.js → scanner-Cb3fSjAC.js} +4 -4
- package/dist/_chunks/{scanner-CKAT5gRx.js.map → scanner-Cb3fSjAC.js.map} +1 -1
- package/dist/_chunks/{walkers-DwCXEyRu.js → walkers-Ber9bamD.js} +3 -3
- package/dist/_chunks/{walkers-DwCXEyRu.js.map → walkers-Ber9bamD.js.map} +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cli.js +3 -3
- package/dist/index.js +6 -6
- package/dist/routing/index.js +2 -2
- package/dist/server/als-registry.d.ts +2 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/internal.js +2 -2
- package/dist/server/internal.js.map +1 -1
- package/dist/server/metadata-collector.d.ts +2 -0
- package/dist/server/metadata-collector.d.ts.map +1 -1
- package/dist/server/metadata-route-links.d.ts +70 -0
- package/dist/server/metadata-route-links.d.ts.map +1 -0
- package/dist/server/metadata-routes.d.ts +0 -24
- package/dist/server/metadata-routes.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/route-matcher.d.ts +7 -0
- package/dist/server/route-matcher.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/server/als-registry.ts +2 -0
- package/src/server/metadata-collector.ts +15 -17
- package/src/server/metadata-route-links.ts +200 -0
- package/src/server/metadata-routes.ts +0 -106
- package/src/server/route-element-builder.ts +1 -0
- package/src/server/route-matcher.ts +2 -2
- package/dist/_chunks/metadata-routes-DSDjM_hJ.js.map +0 -1
|
@@ -29,6 +29,8 @@ export interface MetadataCollectorProps {
|
|
|
29
29
|
metadataExport: Metadata | (() => Promise<Metadata>);
|
|
30
30
|
segmentName: string;
|
|
31
31
|
isPage: boolean;
|
|
32
|
+
/** Index of the owning segment in the route chain. */
|
|
33
|
+
segmentIndex: number;
|
|
32
34
|
children: ReactNode;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-collector.d.ts","sourceRoot":"","sources":["../../src/server/metadata-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"metadata-collector.d.ts","sourceRoot":"","sources":["../../src/server/metadata-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAyC9D,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,QAAQ,GAAG,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,SAAS,CAmB1E;AAID,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,8FAA8F;IAC9F,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CAgC/E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
import type { HeadElement } from './metadata.ts';
|
|
13
|
+
import type { Metadata } from './types.ts';
|
|
14
|
+
import { type ManifestSegmentNode } from './route-matcher.ts';
|
|
15
|
+
/**
|
|
16
|
+
* Segment index whose metadata export supplied the resolved `openGraph.images`
|
|
17
|
+
* and `twitter.images`, or -1 when none did. A file-based `opengraph-image`
|
|
18
|
+
* replaces declared images only from a deeper segment.
|
|
19
|
+
*/
|
|
20
|
+
export interface DeclaredImageOwners {
|
|
21
|
+
openGraph: number;
|
|
22
|
+
twitter: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Find which segment's export supplied the resolved `openGraph.images` and
|
|
26
|
+
* `twitter.images`: the deepest entry whose images are the resolved value.
|
|
27
|
+
* Read off the merge result rather than re-deriving `resolveMetadata`'s merge
|
|
28
|
+
* rule, so the two cannot drift.
|
|
29
|
+
*/
|
|
30
|
+
export declare function findDeclaredImageOwners(entries: {
|
|
31
|
+
metadata: Metadata;
|
|
32
|
+
segmentIndex: number;
|
|
33
|
+
}[], resolved: Metadata): DeclaredImageOwners;
|
|
34
|
+
/** Auto-linked head elements, and the declared metadata they leave in force. */
|
|
35
|
+
export interface MetadataRouteLinks {
|
|
36
|
+
/** `resolvedMetadata` minus any declared images a deeper file replaced. */
|
|
37
|
+
metadata: Metadata;
|
|
38
|
+
elements: HeadElement[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Link metadata route files in the segment chain into the page's head.
|
|
42
|
+
*
|
|
43
|
+
* Walks each segment's metadataRoutes, resolves serve paths and URLs, and
|
|
44
|
+
* emits HeadElement descriptors for <link> and <meta> tags that React Float
|
|
45
|
+
* hoists into <head>.
|
|
46
|
+
*
|
|
47
|
+
* A metadata file is served under the URL of the segment that owns it, not
|
|
48
|
+
* under every descendant URL: a root `app/icon.tsx` rendered on `/map` links
|
|
49
|
+
* `/icon.png`, and `app/posts/[id]/opengraph-image.tsx` on `/posts/42/comments`
|
|
50
|
+
* links `/posts/42/opengraph-image.png`. The owner's prefix is the URL parts
|
|
51
|
+
* the chain has consumed through that segment (`extractUrlParts`, the same
|
|
52
|
+
* walk slot matching uses), filled with the request's raw param values — the
|
|
53
|
+
* parts the metadata route matcher walks back to the same owner.
|
|
54
|
+
*
|
|
55
|
+
* Segments at or below an intercepting segment are skipped: the metadata
|
|
56
|
+
* matcher only walks the canonical tree, so nothing serves their files.
|
|
57
|
+
*
|
|
58
|
+
* Precedence, so no tag is ever emitted twice:
|
|
59
|
+
* - Icon and apple-icon files link from every segment, root to leaf, unless
|
|
60
|
+
* the metadata declares `icons.icon` / `icons.apple`. A declared manifest
|
|
61
|
+
* likewise replaces `app/manifest.*`.
|
|
62
|
+
* - Only the deepest served `opengraph-image` links. It replaces declared
|
|
63
|
+
* `openGraph.images` / `twitter.images` from a shallower segment (those are
|
|
64
|
+
* dropped from the returned metadata) and yields to images declared at its
|
|
65
|
+
* own segment or deeper.
|
|
66
|
+
*
|
|
67
|
+
* See design/16-metadata.md §"Auto-Linking"
|
|
68
|
+
*/
|
|
69
|
+
export declare function linkMetadataRoutes(segments: ManifestSegmentNode[], resolvedMetadata: Metadata, declaredImages: DeclaredImageOwners, requestUrl: URL, rawSegmentParams: Record<string, string | string[]>, metadataRouteHashes?: Record<string, string>): MetadataRouteLinks;
|
|
70
|
+
//# sourceMappingURL=metadata-route-links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-route-links.d.ts","sourceRoot":"","sources":["../../src/server/metadata-route-links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAiBlF;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,EAAE,EACvD,QAAQ,EAAE,QAAQ,GACjB,mBAAmB,CASrB;AAED,gFAAgF;AAChF,MAAM,WAAW,kBAAkB;IACjC,2EAA2E;IAC3E,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,mBAAmB,EAAE,EAC/B,gBAAgB,EAAE,QAAQ,EAC1B,cAAc,EAAE,mBAAmB,EACnC,UAAU,EAAE,GAAG,EACf,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EACnD,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3C,kBAAkB,CA8FpB"}
|
|
@@ -9,9 +9,6 @@
|
|
|
9
9
|
*
|
|
10
10
|
* See design/16-metadata.md §"Metadata Routes"
|
|
11
11
|
*/
|
|
12
|
-
import type { HeadElement } from './metadata.ts';
|
|
13
|
-
import type { Metadata } from './types.ts';
|
|
14
|
-
import type { ManifestSegmentNode } from './route-matcher.ts';
|
|
15
12
|
/** Classification of a metadata route file. */
|
|
16
13
|
export interface MetadataRouteInfo {
|
|
17
14
|
/** The metadata route type. */
|
|
@@ -130,25 +127,4 @@ export type AutoLinkTag = AutoLinkLink | AutoLinkMeta;
|
|
|
130
127
|
* @returns Tag descriptor(s) for the <head>, or null if no auto-link
|
|
131
128
|
*/
|
|
132
129
|
export declare function getMetadataRouteAutoLink(type: MetadataRouteType, href: string): AutoLinkTag[];
|
|
133
|
-
/**
|
|
134
|
-
* Collect auto-linked head elements from metadata route files in the segment chain.
|
|
135
|
-
*
|
|
136
|
-
* Walks each segment's metadataRoutes, resolves serve paths and URLs, and
|
|
137
|
-
* emits HeadElement descriptors for <link> and <meta> tags that React Float
|
|
138
|
-
* hoists into <head>.
|
|
139
|
-
*
|
|
140
|
-
* A metadata file is served under the URL of the segment that owns it, not
|
|
141
|
-
* under every descendant URL: a root `app/icon.tsx` rendered on `/map` links
|
|
142
|
-
* `/icon.png`, and `app/posts/[id]/opengraph-image.tsx` on `/posts/42/comments`
|
|
143
|
-
* links `/posts/42/opengraph-image.png`. The owner's prefix is the URL parts
|
|
144
|
-
* the chain has consumed through that segment (`extractUrlParts`, the same
|
|
145
|
-
* walk slot matching uses), filled with the request's raw param values — the
|
|
146
|
-
* parts the metadata route matcher walks back to the same owner.
|
|
147
|
-
*
|
|
148
|
-
* Segments at or below an intercepting segment are skipped: the metadata
|
|
149
|
-
* matcher only walks the canonical tree, so nothing serves their files.
|
|
150
|
-
*
|
|
151
|
-
* See design/16-metadata.md §"Auto-Linking"
|
|
152
|
-
*/
|
|
153
|
-
export declare function collectMetadataRouteHeadElements(segments: ManifestSegmentNode[], firstDeniedIndex: number, resolvedMetadata: Metadata, requestUrl: URL, rawSegmentParams: Record<string, string | string[]>, metadataRouteHashes?: Record<string, string>): HeadElement[];
|
|
154
130
|
//# sourceMappingURL=metadata-routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-routes.d.ts","sourceRoot":"","sources":["../../src/server/metadata-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"metadata-routes.d.ts","sourceRoot":"","sources":["../../src/server/metadata-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH,+CAA+C;AAC/C,MAAM,WAAW,iBAAiB;IAChC,+BAA+B;IAC/B,IAAI,EAAE,iBAAiB,CAAC;IACxB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,QAAQ,GACR,UAAU,GACV,SAAS,GACT,MAAM,GACN,iBAAiB,GACjB,YAAY,CAAC;AAIjB;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAC7C,MAAM,EACN;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CA8DF,CAAC;AAoBF;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,qBAAqB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAKjG;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAItF;A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ACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,UAAU,EACjB,YAAY,CAAC,EAAE,mBAAmB,EAClC,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,EACxC,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3C,OAAO,CAAC,kBAAkB,CAAC,CAua7B"}
|
|
@@ -97,4 +97,11 @@ export interface MetadataRouteMatch {
|
|
|
97
97
|
* See design/16-metadata.md §"Metadata Routes"
|
|
98
98
|
*/
|
|
99
99
|
export declare function createMetadataRouteMatcher(manifest: ManifestRoot): (pathname: string) => MetadataRouteMatch | null;
|
|
100
|
+
/**
|
|
101
|
+
* Match a pathname against metadata routes in the segment tree.
|
|
102
|
+
*
|
|
103
|
+
* Checks if the last URL part is a known metadata route serve path,
|
|
104
|
+
* then walks the tree to find the segment that owns the route.
|
|
105
|
+
*/
|
|
106
|
+
export declare function matchMetadataRoute(root: ManifestSegmentNode, pathname: string): MetadataRouteMatch | null;
|
|
100
107
|
//# sourceMappingURL=route-matcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-matcher.d.ts","sourceRoot":"","sources":["../../src/server/route-matcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAKL,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAY9B,6DAA6D;AAC7D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,G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AAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAClD;AAcD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,YAAY,GACrB,CAAC,QAAQ,EAAE,MAAM,KAAK,kBAAkB,GAAG,IAAI,CAEjD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,mBAAmB,EACzB,QAAQ,EAAE,MAAM,GACf,kBAAkB,GAAG,IAAI,CAqE3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timber-js/app",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.216",
|
|
4
4
|
"description": "Vite-native React framework built for Servers and Serverless Platforms — correct HTTP semantics, real status codes, pages that work without JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare-workers",
|
|
@@ -184,6 +184,8 @@ export interface RequestContextStore {
|
|
|
184
184
|
_metadataEntries?: Array<{
|
|
185
185
|
metadata: import('./types.ts').Metadata | Promise<import('./types.ts').Metadata | null>;
|
|
186
186
|
isPage: boolean;
|
|
187
|
+
/** Index of the owning segment in the route chain. */
|
|
188
|
+
segmentIndex: number;
|
|
187
189
|
}>;
|
|
188
190
|
}
|
|
189
191
|
|
|
@@ -27,12 +27,13 @@ import { createElement, Fragment } from 'react';
|
|
|
27
27
|
import type { ReactNode } from 'react';
|
|
28
28
|
|
|
29
29
|
import { requestContextAls } from './als-registry.ts';
|
|
30
|
+
import type { RequestContextStore } from './als-registry.ts';
|
|
30
31
|
import type { Metadata } from './types.ts';
|
|
31
32
|
import type { ManifestSegmentNode } from './route-matcher.ts';
|
|
32
33
|
import { withSpan } from './tracing.ts';
|
|
33
34
|
import { resolveMetadata, renderMetadataToElements, headElementsToReact } from './metadata.ts';
|
|
34
35
|
import type { SegmentMetadataEntry } from './metadata.ts';
|
|
35
|
-
import {
|
|
36
|
+
import { findDeclaredImageOwners, linkMetadataRoutes } from './metadata-route-links.ts';
|
|
36
37
|
|
|
37
38
|
// ─── Request-scoped metadata entry store ────────────────────────────────
|
|
38
39
|
|
|
@@ -41,16 +42,13 @@ import { collectMetadataRouteHeadElements } from './metadata-routes.ts';
|
|
|
41
42
|
* concurrent resolution (TIM-1367). Dynamic metadata pushes a promise;
|
|
42
43
|
* static metadata pushes the resolved object directly.
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
-
metadata: Metadata | Promise<Metadata | null>;
|
|
46
|
-
isPage: boolean;
|
|
47
|
-
}
|
|
45
|
+
type DeferredMetadataEntry = NonNullable<RequestContextStore['_metadataEntries']>[number];
|
|
48
46
|
|
|
49
47
|
function getDeferredMetadataEntries(): DeferredMetadataEntry[] {
|
|
50
48
|
const store = requestContextAls.getStore();
|
|
51
49
|
if (!store) return [];
|
|
52
50
|
store._metadataEntries ??= [];
|
|
53
|
-
return store._metadataEntries
|
|
51
|
+
return store._metadataEntries;
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
// ─── MetadataSettle ─────────────────────────────────────────────────────
|
|
@@ -76,6 +74,8 @@ export interface MetadataCollectorProps {
|
|
|
76
74
|
metadataExport: Metadata | (() => Promise<Metadata>);
|
|
77
75
|
segmentName: string;
|
|
78
76
|
isPage: boolean;
|
|
77
|
+
/** Index of the owning segment in the route chain. */
|
|
78
|
+
segmentIndex: number;
|
|
79
79
|
children: ReactNode;
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -92,7 +92,7 @@ export interface MetadataCollectorProps {
|
|
|
92
92
|
* awaits the promise for error ownership.
|
|
93
93
|
*/
|
|
94
94
|
export function MetadataCollector(props: MetadataCollectorProps): ReactNode {
|
|
95
|
-
const { metadataExport, segmentName, isPage, children } = props;
|
|
95
|
+
const { metadataExport, segmentName, isPage, segmentIndex, children } = props;
|
|
96
96
|
|
|
97
97
|
if (typeof metadataExport === 'function') {
|
|
98
98
|
const promise = withSpan('timber.metadata', { 'timber.segment': segmentName }, () =>
|
|
@@ -103,12 +103,12 @@ export function MetadataCollector(props: MetadataCollectorProps): ReactNode {
|
|
|
103
103
|
// Node's unhandledRejection before they do.
|
|
104
104
|
promise.catch(() => {});
|
|
105
105
|
|
|
106
|
-
getDeferredMetadataEntries().push({ metadata: promise, isPage });
|
|
106
|
+
getDeferredMetadataEntries().push({ metadata: promise, isPage, segmentIndex });
|
|
107
107
|
|
|
108
108
|
return createElement(Fragment, null, children, createElement(MetadataSettle, { promise }));
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
getDeferredMetadataEntries().push({ metadata: metadataExport, isPage });
|
|
111
|
+
getDeferredMetadataEntries().push({ metadata: metadataExport, isPage, segmentIndex });
|
|
112
112
|
return children;
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -152,26 +152,24 @@ export async function MetadataHead(props: MetadataHeadProps): Promise<ReactNode>
|
|
|
152
152
|
e.metadata instanceof Promise ? e.metadata : Promise.resolve(e.metadata)
|
|
153
153
|
)
|
|
154
154
|
);
|
|
155
|
-
const entries: SegmentMetadataEntry[] = [];
|
|
155
|
+
const entries: (SegmentMetadataEntry & { segmentIndex: number })[] = [];
|
|
156
156
|
for (let i = 0; i < settled.length; i++) {
|
|
157
157
|
const s = settled[i];
|
|
158
158
|
if (s.status === 'fulfilled' && s.value) {
|
|
159
|
-
|
|
159
|
+
const { isPage, segmentIndex } = deferredEntries[i];
|
|
160
|
+
entries.push({ metadata: s.value, isPage, segmentIndex });
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
const resolved = resolveMetadata(entries);
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
const autoLinked = collectMetadataRouteHeadElements(
|
|
165
|
+
const { metadata, elements } = linkMetadataRoutes(
|
|
167
166
|
segments,
|
|
168
|
-
Infinity,
|
|
169
167
|
resolved,
|
|
168
|
+
findDeclaredImageOwners(entries, resolved),
|
|
170
169
|
new URL(requestUrl),
|
|
171
170
|
rawSegmentParams,
|
|
172
171
|
metadataRouteHashes
|
|
173
172
|
);
|
|
174
|
-
headElements.push(...autoLinked);
|
|
175
173
|
|
|
176
|
-
return headElementsToReact(
|
|
174
|
+
return headElementsToReact([...renderMetadataToElements(metadata), ...elements]);
|
|
177
175
|
}
|
|
@@ -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
|
-
}
|
|
@@ -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) =>
|
|
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
|
|
198
|
+
export function matchMetadataRoute(
|
|
199
199
|
root: ManifestSegmentNode,
|
|
200
200
|
pathname: string
|
|
201
201
|
): MetadataRouteMatch | null {
|