@@ -53,16 +53,13 @@ export type ThemeProps = PropsWithChildren<{
5353
5454export function Theme ( { pageMap, children} : ThemeProps ) {
5555 const pathname = usePathname ( )
56+ const pathHasTrailingSlash = pathname . endsWith ( '/' )
5657
5758 const normalizedPages = normalizePages ( {
5859 list : pageMap ,
5960 route : pathname ,
6061 } )
6162
62- const { activeMetadata} = normalizedPages
63-
64- const { filePath = '' , title = '' } = activeMetadata || { }
65-
6663 const route = usePathname ( )
6764
6865 const fsPath = useFSRoute ( )
@@ -79,33 +76,42 @@ export function Theme({pageMap, children}: ThemeProps) {
7976 // eslint-disable-next-line i18n-text/no-en
8077 const siteTitle = process . env . NEXT_PUBLIC_SITE_TITLE || 'Example Site'
8178 const isHomePage = route === '/'
82- const isIndexPage =
83- / i n d e x \. m d x ? $ / . test ( filePath ) && ! isHomePage && activeMetadata && activeMetadata [ 'show-tabs' ] === undefined
79+
80+ const activeFile = isHomePage
81+ ? undefined
82+ : ( normalizedPages . flatDocsDirectories . find (
83+ item => `${ item . route } ${ pathHasTrailingSlash ? '/' : '' } ` === pathname ,
84+ ) as MdxFile )
85+
86+ const activeMetadata = activeFile ?. frontMatter || { }
87+ const filePath = activeMetadata . filePath || ''
88+ const title = activeMetadata . title || ''
89+
90+ const isIndexPage = / i n d e x \. m d x ? $ / . test ( filePath ) && ! isHomePage && activeMetadata [ 'show-tabs' ] === undefined
8491 const data = ! isHomePage && activePath [ activePath . length - 2 ]
8592 const filteredTabData : MdxFile [ ] = data && hasChildren ( data ) ? ( ( data as Folder ) . children as MdxFile [ ] ) : [ ]
8693
8794 const relatedLinks = getRelatedPages ( route , activeMetadata , flatDocsDirectories )
88- const disablePageAnimation = activeMetadata ?. options ?. disablePageAnimation || false
95+ const disablePageAnimation = activeMetadata . options ?. disablePageAnimation || false
96+
8997 return (
9098 < >
9199 < BrandThemeProvider dir = "ltr" colorMode = { colorMode } >
92100 < ThemeProvider colorMode = { colorMode } >
93101 < BaseStyles >
94- { activeMetadata && (
95- < Head >
96- < title > { title } </ title >
97- { activeMetadata . description && < meta name = "description" content = { activeMetadata . description } /> }
98- < meta property = "og:type" content = "website" />
99- < meta property = "og:title" content = { title } />
100- { activeMetadata . description && < meta property = "og:description" content = { activeMetadata . description } /> }
101- < meta property = "og:image" content = { activeMetadata . image || '/og-image.png' } />
102- { /* X (Twitter) OG */ }
103- < meta name = "twitter:card" content = "summary_large_image" />
104- < meta name = "twitter:title" content = { title } />
105- { activeMetadata . description && < meta name = "twitter:description" content = { activeMetadata . description } /> }
106- < meta name = "twitter:image" content = { activeMetadata . image || '/og-image.png' } />
107- </ Head >
108- ) }
102+ < Head >
103+ < title > { title } </ title >
104+ { activeMetadata . description && < meta name = "description" content = { activeMetadata . description } /> }
105+ < meta property = "og:type" content = "website" />
106+ < meta property = "og:title" content = { title } />
107+ { activeMetadata . description && < meta property = "og:description" content = { activeMetadata . description } /> }
108+ < meta property = "og:image" content = { activeMetadata . image || '/og-image.png' } />
109+ { /* X (Twitter) OG */ }
110+ < meta name = "twitter:card" content = "summary_large_image" />
111+ < meta name = "twitter:title" content = { title } />
112+ { activeMetadata . description && < meta name = "twitter:description" content = { activeMetadata . description } /> }
113+ < meta name = "twitter:image" content = { activeMetadata . image || '/og-image.png' } />
114+ </ Head >
109115
110116 < ContentWrapper disableAnimations = { disablePageAnimation } >
111117 < PRCBox
@@ -159,22 +165,22 @@ export function Theme({pageMap, children}: ThemeProps) {
159165
160166 < Box >
161167 < Stack direction = "vertical" padding = "none" gap = { 12 } alignItems = "flex-start" >
162- { activeMetadata ? .title && (
168+ { activeMetadata . title && (
163169 < Heading as = "h1" size = "3" >
164170 { activeMetadata . title }
165171 </ Heading >
166172 ) }
167- { activeMetadata ? .description && (
173+ { activeMetadata . description && (
168174 < Text as = "p" variant = "muted" size = "300" >
169175 { activeMetadata . description }
170176 </ Text >
171177 ) }
172- { activeMetadata ? .image && (
178+ { activeMetadata . image && (
173179 < Box paddingBlockStart = { 16 } style = { { width : '100%' } } >
174180 < Hero . Image src = { activeMetadata . image } alt = { activeMetadata [ 'image-alt' ] } />
175181 </ Box >
176182 ) }
177- { activeMetadata && activeMetadata [ 'action-1-text' ] && (
183+ { activeMetadata [ 'action-1-text' ] && (
178184 < Box paddingBlockStart = { 16 } >
179185 < ButtonGroup >
180186 < Button as = "a" href = { activeMetadata [ 'action-1-link' ] } >
@@ -190,9 +196,7 @@ export function Theme({pageMap, children}: ThemeProps) {
190196 ) }
191197 </ Stack >
192198 </ Box >
193- { activeMetadata && activeMetadata [ 'show-tabs' ] && (
194- < UnderlineNav tabData = { filteredTabData } />
195- ) }
199+ { activeMetadata [ 'show-tabs' ] && < UnderlineNav tabData = { filteredTabData } /> }
196200 </ >
197201 ) }
198202 < article >
0 commit comments