/
constants.tsx
209 lines (203 loc) · 5.63 KB
/
constants.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
197
198
199
200
201
202
203
204
205
206
207
208
209
/* eslint sort-keys: error */
import React, { isValidElement } from 'react'
import { DocsThemeConfig, PageTheme } from './types'
import { useRouter } from 'next/router'
import { Anchor, Flexsearch, Footer, Navbar, TOC } from './components'
import { DiscordIcon, GitHubIcon } from 'nextra/icons'
import { MatchSorterSearch } from './components/match-sorter-search'
import { useConfig } from './contexts'
import { getGitEditUrl } from './utils'
export const DEFAULT_LOCALE = 'en-US'
export const IS_BROWSER = typeof window !== 'undefined'
export const DEFAULT_THEME: DocsThemeConfig = {
banner: {
dismissible: true,
key: 'nextra-banner'
},
chat: {
icon: (
<>
<DiscordIcon />
<span className="nx-sr-only">Discord</span>
</>
)
},
darkMode: true,
direction: 'ltr',
docsRepositoryBase: 'https://github.com/shuding/nextra',
editLink: {
component({ className, filePath, children }) {
const editUrl = getGitEditUrl(filePath)
if (!editUrl) {
return null
}
return (
<Anchor className={className} href={editUrl}>
{children}
</Anchor>
)
},
text: 'Edit this page'
},
feedback: {
content: () => <>Question? Give us feedback →</>,
labels: 'feedback'
},
footer: {
component: Footer,
text: `MIT ${new Date().getFullYear()} © Nextra.`
},
getNextSeoProps: () => ({ titleTemplate: '%s – Nextra' }),
gitTimestamp({ timestamp }) {
const { locale = DEFAULT_LOCALE } = useRouter()
return (
<>
Last updated on{' '}
{timestamp.toLocaleDateString(locale, {
day: 'numeric',
month: 'long',
year: 'numeric'
})}
</>
)
},
head: (
<>
<meta name="msapplication-TileColor" content="#fff" />
<meta httpEquiv="Content-Language" content="en" />
<meta name="description" content="Nextra: the next docs builder" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@shuding_" />
<meta property="og:title" content="Nextra: the next docs builder" />
<meta property="og:description" content="Nextra: the next docs builder" />
<meta name="apple-mobile-web-app-title" content="Nextra" />
</>
),
i18n: [],
logo: (
<>
<span className="nx-font-extrabold">Nextra</span>
<span className="nx-ml-2 nx-hidden nx-font-normal nx-text-gray-600 md:nx-inline">
The Next Docs Builder
</span>
</>
),
logoLink: true,
navbar: {
component: Navbar
},
navigation: true,
nextThemes: {
defaultTheme: 'system',
storageKey: 'theme'
},
notFound: {
content: 'Submit an issue about broken link →',
labels: 'bug'
},
primaryHue: {
dark: 204,
light: 212
},
project: {
icon: (
<>
<GitHubIcon />
<span className="nx-sr-only">GitHub</span>
</>
)
},
search: {
component({ className, directories }) {
const config = useConfig()
return config.flexsearch ? (
<Flexsearch className={className} />
) : (
<MatchSorterSearch className={className} directories={directories} />
)
},
emptyResult: (
<span className="nx-block nx-select-none nx-p-8 nx-text-center nx-text-sm nx-text-gray-400">
No results found.
</span>
),
loading() {
const { locale } = useRouter()
if (locale === 'zh-CN') return '正在加载…'
if (locale === 'ru') return 'Загрузка…'
if (locale === 'fr') return 'Сhargement…'
return 'Loading…'
},
placeholder() {
const { locale } = useRouter()
if (locale === 'zh-CN') return '搜索文档…'
if (locale === 'ru') return 'Поиск документации…'
if (locale === 'fr') return 'Rechercher de la documentation…'
return 'Search documentation…'
}
},
serverSideError: {
content: 'Submit an issue about error in url →',
labels: 'bug'
},
sidebar: {
defaultMenuCollapseLevel: 2,
titleComponent: ({ title }) => <>{title}</>
},
toc: {
component: TOC,
float: true,
title: 'On This Page'
}
}
export const DEEP_OBJECT_KEYS = Object.entries(DEFAULT_THEME)
.map(([key, value]) => {
const isObject =
value &&
typeof value === 'object' &&
!Array.isArray(value) &&
!isValidElement(value)
if (isObject) {
return key
}
})
.filter(Boolean) as (keyof DocsThemeConfig)[]
export const LEGACY_CONFIG_OPTIONS: Record<string, string> = {
bannerKey: 'banner.key',
bodyExtraContent: 'main',
customSearch: 'search.component',
defaultMenuCollapsed: 'sidebar.defaultMenuCollapseLevel',
feedbackLabels: 'feedback.labels',
feedbackLink: 'feedback.content',
floatTOC: 'toc.float',
footerEditLink: 'editLink.text',
footerText: 'footer.text',
github: 'project.link',
nextLinks: 'navigation.next',
notFoundLabels: 'notFound.labels',
notFoundLink: 'notFound.content',
prevLinks: 'navigation.prev',
projectChat: 'chat',
projectChatLink: 'chat.link',
projectChatLinkIcon: 'chat.icon',
projectLink: 'project.link',
projectLinkIcon: 'project.icon',
searchPlaceholder: 'search.placeholder',
serverSideErrorLabels: 'serverSideError.labels',
serverSideErrorLink: 'serverSideError.content',
sidebarSubtitle: 'sidebar.titleComponent',
tocExtraContent: 'toc.extraContent',
unstable_searchResultEmpty: 'search.emptyResult'
}
export const DEFAULT_PAGE_THEME: PageTheme = {
breadcrumb: true,
collapsed: false,
footer: true,
layout: 'default',
navbar: true,
pagination: true,
sidebar: true,
timestamp: true,
toc: true,
typesetting: 'default'
}