forked from pluralsh/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_app.tsx
147 lines (130 loc) · 3.96 KB
/
_app.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
import { MarkdocNextJsPageProps } from '@markdoc/next.js'
import styled, { ThemeProvider as StyledThemeProvider } from 'styled-components'
import {
FillLevelProvider,
GlobalStyle as PluralGlobalStyle,
theme as honorableTheme,
styledTheme,
} from '@pluralsh/design-system'
import { CssBaseline, ThemeProvider } from 'honorable'
import { SSRProvider } from '@react-aria/ssr'
import '../src/styles/globals.css'
import { useRouter } from 'next/router'
import { BreakpointProvider } from '../src/components/Breakpoints'
import PageFooter from '../src/components/PageFooter'
import HtmlHead from '../src/components/HtmlHead'
import { NavPositionWrapper, SideNav } from '../src/components/SideNav'
import ExternalScripts from '../src/components/ExternalScripts'
import { TableOfContents } from '../src/components/TableOfContents'
import { PageHeader } from '../src/components/PageHeader'
import {
ContentContainer,
PageGrid,
SideCarContainer,
SideNavContainer,
} from '../src/components/PageGrid'
import GlobalStyles from '../src/components/GlobalStyles'
import DocSearchStyles from '../src/components/DocSearchStyles'
import MainContent from '../src/components/MainContent'
import {
DESCRIPTION,
PAGE_TITLE_PREFIX,
PAGE_TITLE_SUFFIX,
ROOT_TITLE,
} from '../src/consts'
import { PagePropsContext } from '../src/components/PagePropsContext'
import navData from '../src/NavData'
import type { AppProps } from 'next/app'
type AppPropsPlusMd = AppProps & { pageProps: MarkdocNextJsPageProps }
export type MarkdocHeading = {
id?: string
level?: number
title?: string
}
const docsStyledTheme = { ...styledTheme, ...{ docs: { topNavHeight: 72 } } }
function collectHeadings(node, sections: MarkdocHeading[] = []) {
if (node) {
if (node?.name === 'Heading') {
const title = node.children[0]
if (typeof title === 'string') {
sections.push({
...node.attributes,
title,
})
}
}
if (node?.children) {
for (const child of node.children) {
collectHeadings(child, sections)
}
}
}
return sections as MarkdocHeading[]
}
const Page = styled.div(() => ({}))
function MyApp({ Component, pageProps }: AppPropsPlusMd) {
const router = useRouter()
const { markdoc } = pageProps
const title = markdoc?.frontmatter?.title
? `${PAGE_TITLE_PREFIX}${markdoc?.frontmatter?.title}${PAGE_TITLE_SUFFIX}`
: ROOT_TITLE
const description
= router.pathname === '/'
? DESCRIPTION
: markdoc?.frontmatter?.description || DESCRIPTION
const toc = pageProps.markdoc?.content
? collectHeadings(pageProps.markdoc.content)
: []
const app = (
<>
<CssBaseline />
<PluralGlobalStyle />
<GlobalStyles />
<DocSearchStyles />
<PagePropsContext.Provider value={pageProps}>
<HtmlHead
title={title}
description={description}
/>
<PageHeader />
<Page>
<PageGrid>
<SideNavContainer>
<NavPositionWrapper
role="navigation"
aria-label="Main"
>
<SideNav
navData={navData}
desktop
/>
</NavPositionWrapper>
</SideNavContainer>
<ContentContainer>
<MainContent Component={Component} />
<PageFooter />
</ContentContainer>
<SideCarContainer>
<TableOfContents toc={toc} />
</SideCarContainer>
</PageGrid>
</Page>
<ExternalScripts />
</PagePropsContext.Provider>
</>
)
return (
<SSRProvider>
<BreakpointProvider>
<ThemeProvider theme={honorableTheme}>
<StyledThemeProvider theme={docsStyledTheme}>
<FillLevelProvider value={0}>
{app}
</FillLevelProvider>
</StyledThemeProvider>
</ThemeProvider>
</BreakpointProvider>
</SSRProvider>
)
}
export default MyApp