Repository navigation
Expand file tree
/
Copy pathdocusaurus.config.js
More file actions
251 lines (233 loc) · 8.63 KB
/
Copy pathdocusaurus.config.js
File metadata and controls
251 lines (233 loc) · 8.63 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion
import { topbarBannerReservationScript } from '@swmansion/t-rex-ui/topbar-banner';
import { TOP_BAR_BANNER } from './src/components/topbarBanner.config.ts';
const path = require('path');
const webpack = require('webpack');
// Interactive examples import the library's web build directly from the
// monorepo (this docs folder is a standalone yarn project that does not
// depend on the workspace package). Alias the bare specifier to the
// prebuilt web bundle so `EnrichedMarkdownText` renders live in the browser.
// KaTeX is a real docs dependency (`loadKaTeX` requires it at runtime) so the
// `latexMath` playground renders math; its stylesheet is loaded via a client
// module (`src/clientModules/katexStyles.ts`).
const enrichedMarkdownWebEntry = path.resolve(
__dirname,
'../packages/react-native-enriched-markdown/lib/module/index.web.js',
);
const lightCodeTheme = require('./src/theme/CodeBlock/highlighting-light.js');
const darkCodeTheme = require('./src/theme/CodeBlock/highlighting-dark.js');
const baseUrl = '/enriched-markdown/';
const firstBannerZone = TOP_BAR_BANNER.zones[0];
const bannerReservationHeadTags = firstBannerZone
? [
{
tagName: 'script',
attributes: { type: 'text/javascript' },
innerHTML: topbarBannerReservationScript(
firstBannerZone.zoneId,
firstBannerZone.contentId,
TOP_BAR_BANNER.hiddenPaths,
),
},
]
: [];
/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'Enriched Markdown',
favicon: 'img/favicon.png',
url: 'https://docs.swmansion.com',
baseUrl,
organizationName: 'software-mansion',
projectName: 'enriched-markdown',
onBrokenLinks: 'throw',
onBrokenAnchors: 'throw',
markdown: {
hooks: {
onBrokenMarkdownLinks: 'throw',
},
mermaid: true,
},
themes: ['@docusaurus/theme-mermaid'],
i18n: {
defaultLocale: 'en',
locales: ['en'],
},
presets: [
[
'classic',
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
routeBasePath: '/',
breadcrumbs: false,
sidebarPath: require.resolve('./sidebars.js'),
// Categories are non-collapsible by default; the per-platform
// sections opt back in via `collapsible: true` in their
// `_category_.json` so they render as collapsible ("burger") groups.
sidebarCollapsible: false,
exclude: [
'**/_*.{js,jsx,ts,tsx,md,mdx}',
'**/_*/**',
'**/*.test.{js,jsx,ts,tsx}',
'**/__tests__/**',
],
editUrl:
'https://github.com/software-mansion/enriched-markdown/edit/main/docs/',
lastVersion: 'current',
},
theme: {
customCss: require.resolve('./src/css/index.css'),
},
}),
],
],
headTags: [
// Docusaurus renders the `favicon` link through Helmet (client-side only),
// so the dev server's HTML ships without it and the browser falls back to
// requesting `/favicon.ico` at the origin root - which the dev server
// answers with the SPA HTML. Emitting the tag here puts it in the initial
// markup in dev and prod alike. `headTags` hrefs are not baseUrl-prefixed
// automatically, hence the explicit prefix.
{
tagName: 'link',
attributes: {
rel: 'icon',
type: 'image/png',
href: `${baseUrl}img/favicon.png`,
},
},
...bannerReservationHeadTags,
],
clientModules: [
require.resolve('./src/clientModules/topbarBannerRefresh.ts'),
require.resolve('./src/clientModules/katexStyles.ts'),
],
plugins: [
process.env.NODE_ENV === 'production' && [
'@docusaurus/plugin-google-tag-manager',
{
containerId: 'GTM-N5QK8TMT',
},
],
function enrichedMarkdownAliasPlugin() {
return {
name: 'enriched-markdown-web-alias',
configureWebpack(config) {
return {
plugins: [
// React Native code (reached through the library's web build)
// references the `__DEV__` global that Metro/babel injects but
// webpack does not, so define it here to match the bundle mode.
new webpack.DefinePlugin({
__DEV__: JSON.stringify(config.mode !== 'production'),
}),
],
resolve: {
alias: {
// The library's web build reaches into react-native
// (Platform/processColor via styleUtils), so it needs the
// standard react-native-web alias to bundle for the browser.
'react-native$': 'react-native-web',
'react-native-enriched-markdown': enrichedMarkdownWebEntry,
// The web build's `require('katex')` lives under packages/, so
// webpack would resolve it from there and miss the copy
// installed in this docs project. Alias it to the docs katex so
// the resolution succeeds wherever the require sits.
katex: path.dirname(require.resolve('katex/package.json')),
},
},
module: {
rules: [
{
// The web build's markdown parser does a dynamic
// `import('./wasm/md4c')` without a file extension; the lib
// is ESM ("type": "module"), so webpack otherwise rejects
// the non-fully-specified request.
test: /\.m?js$/,
resolve: { fullySpecified: false },
},
{
// The emscripten glue (md4c.js) is a UMD/CommonJS file, but it
// ships inside the library's ESM build (lib/module,
// "type": "module"). Parsed as ESM its `module.exports`
// factory is dropped, so `import('./wasm/md4c').default` is
// undefined and parsing silently falls back to raw text.
// Force CJS interop so the factory resolves as `.default`.
test: /md4c\.js$/,
type: 'javascript/auto',
},
{
// The web build loads KaTeX with a CommonJS `require('katex')`
// inside `lib/module/web/katex.js`. Because lib/module is
// strict ESM ("type": "module"), webpack leaves that `require`
// untransformed - at runtime `require` is undefined, the
// throw is swallowed, and math silently falls back to raw
// text. Forcing this file to `javascript/auto` lets webpack
// process the `require` (resolved via the `katex` alias above)
// while its `export` still works.
test: /lib[/\\]module[/\\]web[/\\]katex\.js$/,
type: 'javascript/auto',
},
],
},
};
},
};
},
].filter(Boolean),
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
image: 'img/og-image.png',
metadata: [
{ name: 'og:image:width', content: '1200' },
{ name: 'og:image:height', content: '630' },
],
colorMode: {
respectPrefersColorScheme: true,
},
navbar: {
hideOnScroll: false,
logo: {
alt: 'Enriched Markdown logo',
src: 'img/logo.svg',
srcDark: 'img/logo-dark.svg',
},
items: [
{
to: '/getting-started',
label: 'Docs',
position: 'right',
},
{
href: 'https://github.com/software-mansion/enriched-markdown/',
position: 'right',
className: 'header-github',
'aria-label': 'GitHub repository',
},
],
},
footer: {
style: 'light',
links: [],
copyright:
'All trademarks and copyrights belong to their respective owners.',
},
prism: {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
additionalLanguages: ['bash', 'diff', 'json', 'mermaid'],
},
// TODO: replace placeholders with real DocSearch credentials once
// Algolia approval lands. Required so preset-classic activates
// @docusaurus/theme-search-algolia and `@theme/SearchTranslations`
// alias resolves during build.
algolia: {
appId: 'PLACEHOLDER_APP_ID',
apiKey: 'PLACEHOLDER_API_KEY',
indexName: 'react-native-enriched-markdown',
},
}),
};
module.exports = config;