@@ -8,6 +8,7 @@ import { useRouter } from 'next/router'
8
8
import type { FC , ReactElement } from 'react'
9
9
import { NEXTRA_INTERNAL } from './constants'
10
10
import { SSGContext } from './data'
11
+ import { pageTitleFromFilename } from './server/utils'
11
12
import type {
12
13
DynamicFolder ,
13
14
DynamicMeta ,
@@ -19,7 +20,7 @@ import type {
19
20
PageMapItem ,
20
21
PageOpts
21
22
} from './types'
22
- import { normalizePageRoute , pageTitleFromFilename } from './utils'
23
+ import { normalizePageRoute } from './utils'
23
24
24
25
function isFolder ( value : DynamicMetaItem ) : value is DynamicFolder {
25
26
return ! ! value && typeof value === 'object' && value . type === 'folder'
@@ -32,10 +33,10 @@ function normalizeMetaData(obj: DynamicMeta): DynamicMeta {
32
33
const keyWithoutSlash = key . replace ( '/' , '' )
33
34
return [
34
35
keyWithoutSlash ,
35
- value . title || /* @__PURE__ */ pageTitleFromFilename ( keyWithoutSlash )
36
+ value . title || pageTitleFromFilename ( keyWithoutSlash )
36
37
]
37
38
}
38
- return [ key , value || /* @__PURE__ */ pageTitleFromFilename ( key ) ]
39
+ return [ key , value || pageTitleFromFilename ( key ) ]
39
40
} )
40
41
)
41
42
}
@@ -57,7 +58,7 @@ export function collectCatchAllRoutes(
57
58
}
58
59
parent . children . push ( {
59
60
name : key ,
60
- route : /* @__PURE__ */ normalizePageRoute ( parent . route , key )
61
+ route : normalizePageRoute ( parent . route , key )
61
62
} )
62
63
continue
63
64
}
@@ -75,37 +76,37 @@ export function collectCatchAllRoutes(
75
76
76
77
let cachedResolvedPageMap : PageMapItem [ ]
77
78
79
+ export const resolvePageMap =
80
+ ( dynamicMetaModules : [ ( ) => any , DynamicMetaDescriptor ] [ ] ) => async ( ) => {
81
+ const __nextra_internal__ = ( globalThis as NextraInternalGlobal ) [
82
+ NEXTRA_INTERNAL
83
+ ]
84
+ if ( process . env . NODE_ENV === 'production' && cachedResolvedPageMap ) {
85
+ return cachedResolvedPageMap
86
+ }
87
+ const clonedPageMap = structuredClone ( __nextra_internal__ . pageMap )
88
+ for ( const [
89
+ metaFunction ,
90
+ { metaObjectKeyPath, metaParentKeyPath }
91
+ ] of dynamicMetaModules ) {
92
+ const metaData = await metaFunction ( )
93
+ const meta : DynamicMetaJsonFile = get ( clonedPageMap , metaObjectKeyPath )
94
+ meta . data = metaData
95
+ const parent : Folder = get ( clonedPageMap , metaParentKeyPath )
96
+ collectCatchAllRoutes ( parent , meta )
97
+ }
98
+ return ( cachedResolvedPageMap = clonedPageMap )
99
+ }
100
+
78
101
export function setupNextraPage ( {
79
102
pageOpts,
80
103
MDXContent,
81
- dynamicMetaModules = [ ] ,
82
104
route
83
105
} : {
84
106
pageOpts : PageOpts
85
107
MDXContent : FC
86
- dynamicMetaModules ?: [ ( ) => any , DynamicMetaDescriptor ] [ ]
87
108
route : string
88
109
} ) {
89
- if ( typeof window === 'undefined' ) {
90
- globalThis . __nextra_resolvePageMap = async ( ) => {
91
- if ( process . env . NODE_ENV === 'production' && cachedResolvedPageMap ) {
92
- return cachedResolvedPageMap
93
- }
94
- const clonedPageMap = structuredClone ( __nextra_internal__ . pageMap )
95
- for ( const [
96
- metaFunction ,
97
- { metaObjectKeyPath, metaParentKeyPath }
98
- ] of dynamicMetaModules ) {
99
- const metaData = await metaFunction ( )
100
- const meta : DynamicMetaJsonFile = get ( clonedPageMap , metaObjectKeyPath )
101
- meta . data = metaData
102
- const parent : Folder = get ( clonedPageMap , metaParentKeyPath )
103
- collectCatchAllRoutes ( parent , meta )
104
- }
105
- return ( cachedResolvedPageMap = clonedPageMap )
106
- }
107
- }
108
-
109
110
// Make sure the same component is always returned so Next.js will render the
110
111
// stable layout. We then put the actual content into a global store and use
111
112
// the route to identify it.
0 commit comments