-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathPageBody.tsx
161 lines (153 loc) · 6.14 KB
/
PageBody.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
import {
CustomizationSettings,
JSONDocument,
RevisionPageDocument,
SiteCustomizationSettings,
Space,
} from '@gitbook/api';
import React from 'react';
import { getSpaceLanguage } from '@/intl/server';
import { t } from '@/intl/translate';
import { ContentTarget, SiteContentPointer, api } from '@/lib/api';
import { hasFullWidthBlock, isNodeEmpty } from '@/lib/document';
import { ContentRefContext, resolveContentRef } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
import { shouldTrackPageViews } from '@/lib/tracking';
import { PageBodyBlankslate } from './PageBodyBlankslate';
import { PageCover } from './PageCover';
import { PageFooterNavigation } from './PageFooterNavigation';
import { PageHeader } from './PageHeader';
import { PreservePageLayout } from './PreservePageLayout';
import { TrackPageView } from './TrackPageView';
import { DocumentView, DocumentViewSkeleton, createHighlightingContext } from '../DocumentView';
import { PageFeedbackForm } from '../PageFeedback';
import { DateRelative } from '../primitives';
export function PageBody(props: {
space: Space;
pointer: SiteContentPointer;
contentTarget: ContentTarget;
customization: CustomizationSettings | SiteCustomizationSettings;
page: RevisionPageDocument;
document: JSONDocument | null;
context: ContentRefContext;
withPageFeedback: boolean;
}) {
const {
space,
pointer,
contentTarget,
customization,
context,
page,
document,
withPageFeedback,
} = props;
const asFullWidth = document ? hasFullWidthBlock(document) : false;
const language = getSpaceLanguage(customization);
const updatedAt = page.updatedAt ?? page.createdAt;
const shouldHighlightCode = createHighlightingContext();
return (
<>
<main
className={
tcls(
'flex-1',
'relative',
'py-8',
'lg:px-12',
// Allow words to break if they are too long.
'break-anywhere',
// When in api page mode without the aside, we align with the border of the main content
'page-api-block:xl:max-2xl:pr-0',
// Max size to ensure one column in api is aligned with rest of content (2 x 3xl) + (gap-3 + 2) * px-12
'page-api-block:max-w-[1654px]',
'page-api-block:mx-auto',
page.layout.outline ? null : 'xl:mr-56',
page.layout.tableOfContents ? null : 'xl:ml-56',
) +
(asFullWidth ? ' page-full-width' : '') +
(!page.layout.tableOfContents ? ' page-no-toc' : '')
}
>
<PreservePageLayout asFullWidth={asFullWidth} />
{page.cover && page.layout.cover && page.layout.coverSize === 'hero' ? (
<PageCover as="hero" page={page} cover={page.cover} context={context} />
) : null}
<PageHeader page={page} />
{document && !isNodeEmpty(document) ? (
<React.Suspense
fallback={
<DocumentViewSkeleton
document={document}
blockStyle={['page-api-block:ml-0']}
/>
}
>
<DocumentView
document={document}
style={['[&>*+*]:mt-5', 'grid']}
blockStyle={['page-api-block:ml-0']}
context={{
mode: 'default',
content: contentTarget,
contentRefContext: context,
resolveContentRef: (ref, options) =>
resolveContentRef(ref, context, options),
shouldHighlightCode,
}}
/>
</React.Suspense>
) : (
<PageBodyBlankslate page={page} rootPages={context.pages} context={context} />
)}
{page.layout.pagination && customization.pagination.enabled ? (
<PageFooterNavigation
space={space}
customization={customization}
pages={context.pages}
page={page}
/>
) : null}
<div
className={tcls(
'flex',
'flex-row',
'items-center',
'mt-6',
'max-w-3xl',
'mx-auto',
'page-api-block:ml-0',
)}
>
{updatedAt ? (
<p
className={tcls(
'flex-1',
'text-sm',
'text-dark/6',
'dark:text-light/5',
)}
>
{t(language, 'page_last_modified', <DateRelative value={updatedAt} />)}
</p>
) : null}
{withPageFeedback ? (
<PageFeedbackForm
orientation="horizontal"
spaceId={space.id}
pageId={page.id}
/>
) : null}
</div>
</main>
{shouldTrackPageViews() ? (
<TrackPageView
sitePointer={pointer}
spaceId={space.id}
pageId={page.id}
apiHost={api().endpoint}
/>
) : null}
</>
);
}