@@ -6,52 +6,86 @@ import {Suspense} from 'react';
66import * as React from 'react' ;
77import { useRouter } from 'next/router' ;
88import { Nav } from './Nav' ;
9- import { RouteItem , SidebarContext } from './useRouteMeta' ;
10- import { useActiveSection } from 'hooks/useActiveSection' ;
119import { Footer } from './Footer' ;
1210import { Toc } from './Toc' ;
1311import SocialBanner from '../SocialBanner' ;
12+ import { DocsPageFooter } from 'components/DocsFooter' ;
13+ import { Seo } from 'components/Seo' ;
14+ import PageHeading from 'components/PageHeading' ;
15+ import { getRouteMeta } from './getRouteMeta' ;
16+ import { TocContext } from '../MDX/TocContext' ;
1417import sidebarLearn from '../../sidebarLearn.json' ;
1518import sidebarReference from '../../sidebarReference.json' ;
1619import type { TocItem } from 'components/MDX/TocContext' ;
20+ import type { RouteItem } from 'components/Layout/getRouteMeta' ;
21+
22+ import ( /* webpackPrefetch: true */ '../MDX/CodeBlock/CodeBlock' ) ;
1723
1824interface PageProps {
1925 children : React . ReactNode ;
2026 toc : Array < TocItem > ;
27+ routeTree : RouteItem ;
28+ meta : { title ?: string ; description ?: string } ;
29+ section : 'learn' | 'reference' | 'home' ;
2130}
2231
23- export function Page ( { children, toc} : PageProps ) {
32+ export function Page ( { children, toc, routeTree , meta , section } : PageProps ) {
2433 const { asPath} = useRouter ( ) ;
25- const section = useActiveSection ( ) ;
26- let routeTree = sidebarLearn as RouteItem ;
27- switch ( section ) {
28- case 'reference' :
29- routeTree = sidebarReference as RouteItem ;
30- break ;
31- }
34+ const cleanedPath = asPath . split ( / [ \? \# ] / ) [ 0 ] ;
35+ const { route, nextRoute, prevRoute, breadcrumbs} = getRouteMeta (
36+ cleanedPath ,
37+ routeTree
38+ ) ;
39+ const title = meta . title || route ?. title || '' ;
40+ const description = meta . description || route ?. description || '' ;
41+ const isHomePage = cleanedPath === '/' ;
3242 return (
3343 < >
3444 < SocialBanner />
35- < SidebarContext . Provider value = { routeTree } >
36- < div className = "grid grid-cols-only-content lg:grid-cols-sidebar-content 2xl:grid-cols-sidebar-content-toc" >
37- < div className = "fixed lg:sticky top-0 left-0 right-0 py-0 shadow lg:shadow-none z-50" >
38- < Nav />
39- </ div >
40- { /* No fallback UI so need to be careful not to suspend directly inside. */ }
41- < Suspense fallback = { null } >
42- < main className = "min-w-0" >
43- < div className = "lg:hidden h-16 mb-2" />
44- < article className = "break-words" key = { asPath } >
45- { children }
46- </ article >
47- < Footer />
48- </ main >
49- </ Suspense >
50- < div className = "hidden lg:max-w-xs 2xl:block" >
51- { toc . length > 0 && < Toc headings = { toc } key = { asPath } /> }
52- </ div >
45+ < div className = "grid grid-cols-only-content lg:grid-cols-sidebar-content 2xl:grid-cols-sidebar-content-toc" >
46+ < div className = "fixed lg:sticky top-0 left-0 right-0 py-0 shadow lg:shadow-none z-50" >
47+ < Nav
48+ routeTree = { routeTree }
49+ breadcrumbs = { breadcrumbs }
50+ section = { section }
51+ />
52+ </ div >
53+ { /* No fallback UI so need to be careful not to suspend directly inside. */ }
54+ < Suspense fallback = { null } >
55+ < main className = "min-w-0" >
56+ < div className = "lg:hidden h-16 mb-2" />
57+ < article className = "break-words" key = { asPath } >
58+ < div className = "pl-0" >
59+ < Seo title = { title } />
60+ { ! isHomePage && (
61+ < PageHeading
62+ title = { title }
63+ description = { description }
64+ tags = { route ?. tags }
65+ breadcrumbs = { breadcrumbs }
66+ />
67+ ) }
68+ < div className = "px-5 sm:px-12" >
69+ < div className = "max-w-7xl mx-auto" >
70+ < TocContext . Provider value = { toc } >
71+ { children }
72+ </ TocContext . Provider >
73+ </ div >
74+ < DocsPageFooter
75+ route = { route }
76+ nextRoute = { nextRoute }
77+ prevRoute = { prevRoute }
78+ />
79+ </ div >
80+ </ div >
81+ </ article >
82+ < Footer />
83+ </ main >
84+ </ Suspense >
85+ < div className = "hidden lg:max-w-xs 2xl:block" >
86+ { toc . length > 0 && < Toc headings = { toc } key = { asPath } /> }
5387 </ div >
54- </ SidebarContext . Provider >
88+ </ div >
5589 </ >
5690 ) ;
5791}
0 commit comments