-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPage.tsx
196 lines (188 loc) · 5.61 KB
/
Page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/
import {Suspense} from 'react';
import * as React from 'react';
import {useRouter} from 'next/router';
import {SidebarNav} from './SidebarNav';
import {Footer} from './Footer';
import {Toc} from './Toc';
// import SocialBanner from '../SocialBanner';
import {DocsPageFooter} from 'components/DocsFooter';
import {Seo} from 'components/Seo';
import PageHeading from 'components/PageHeading';
import {getRouteMeta} from './getRouteMeta';
import {TocContext} from '../MDX/TocContext';
import {Languages, LanguagesContext} from '../MDX/LanguagesContext';
import type {TocItem} from 'components/MDX/TocContext';
import type {RouteItem} from 'components/Layout/getRouteMeta';
import {HomeContent} from './HomeContent';
import {TopNav} from './TopNav';
import cn from 'classnames';
import Head from 'next/head';
import(/* webpackPrefetch: true */ '../MDX/CodeBlock/CodeBlock');
interface PageProps {
children: React.ReactNode;
toc: Array<TocItem>;
routeTree: RouteItem;
meta: {
title?: string;
titleForTitleTag?: string;
canary?: boolean;
description?: string;
};
section: 'learn' | 'reference' | 'community' | 'blog' | 'home' | 'unknown';
languages?: Languages | null;
}
export function Page({
children,
toc,
routeTree,
meta,
section,
languages = null,
}: PageProps) {
const {asPath} = useRouter();
const cleanedPath = asPath.split(/[\?\#]/)[0];
const {route, nextRoute, prevRoute, breadcrumbs, order} = getRouteMeta(
cleanedPath,
routeTree
);
const title = meta.title || route?.title || '';
const canary = meta.canary || false;
const description = meta.description || route?.description || '';
const isHomePage = cleanedPath === '/';
const isBlogIndex = cleanedPath === '/blog';
let content;
if (isHomePage) {
content = <HomeContent />;
} else {
content = (
<div className="ps-0">
<div
className={cn(
section === 'blog' && 'mx-auto px-0 lg:px-4 max-w-5xl'
)}>
<PageHeading
title={title}
canary={canary}
description={description}
tags={route?.tags}
breadcrumbs={breadcrumbs}
/>
</div>
<div className="px-5 sm:px-12">
<div
className={cn(
'max-w-7xl mx-auto',
section === 'blog' && 'lg:flex lg:flex-col lg:items-center'
)}>
<TocContext.Provider value={toc}>
<LanguagesContext.Provider value={languages}>
{children}
</LanguagesContext.Provider>
</TocContext.Provider>
</div>
{!isBlogIndex && (
<DocsPageFooter
route={route}
nextRoute={nextRoute}
prevRoute={prevRoute}
/>
)}
</div>
</div>
);
}
let hasColumns = true;
let showSidebar = true;
let showToc = true;
if (isHomePage || isBlogIndex) {
hasColumns = false;
showSidebar = false;
showToc = false;
} else if (section === 'blog') {
showToc = false;
hasColumns = false;
showSidebar = false;
}
let searchOrder;
if (section === 'learn' || (section === 'blog' && !isBlogIndex)) {
searchOrder = order;
}
return (
<>
<Seo
title={title}
titleForTitleTag={meta.titleForTitleTag}
isHomePage={isHomePage}
image={`/images/og-` + section + '.png'}
searchOrder={searchOrder}
/>
{(isHomePage || isBlogIndex) && (
<Head>
<link
rel="alternate"
type="application/rss+xml"
title="React Blog RSS Feed"
href="/rss.xml"
/>
</Head>
)}
{/*<SocialBanner />*/}
<TopNav
section={section}
routeTree={routeTree}
breadcrumbs={breadcrumbs}
/>
<div
className={cn(
hasColumns &&
'grid grid-cols-only-content lg:grid-cols-sidebar-content 2xl:grid-cols-sidebar-content-toc'
)}>
{showSidebar && (
<div className="lg:-mt-16 z-10">
<div className="fixed top-0 py-0 shadow lg:pt-16 lg:sticky start-0 end-0 lg:shadow-none">
<SidebarNav
key={section}
routeTree={routeTree}
breadcrumbs={breadcrumbs}
/>
</div>
</div>
)}
{/* No fallback UI so need to be careful not to suspend directly inside. */}
<Suspense fallback={null}>
<main className="min-w-0 isolate">
<article
className="font-normal break-words text-primary dark:text-primary-dark"
key={asPath}>
{content}
</article>
<div
className={cn(
'self-stretch w-full',
isHomePage && 'bg-wash dark:bg-gray-95 mt-[-1px]'
)}>
{!isHomePage && (
<div className="w-full px-5 pt-10 mx-auto sm:px-12 md:px-12 md:pt-12 lg:pt-10">
<hr className="mx-auto max-w-7xl border-border dark:border-border-dark" />
</div>
)}
<div
className={cn(
'py-12 px-5 sm:px-12 md:px-12 sm:py-12 md:py-16 lg:py-14',
isHomePage && 'lg:pt-0'
)}>
<Footer />
</div>
</div>
</main>
</Suspense>
<div className="hidden -mt-16 lg:max-w-custom-xs 2xl:block">
{showToc && toc.length > 0 && <Toc headings={toc} key={asPath} />}
</div>
</div>
</>
);
}