-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocusaurus.config.ts
More file actions
426 lines (389 loc) · 11.1 KB
/
docusaurus.config.ts
File metadata and controls
426 lines (389 loc) · 11.1 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
import fs from "node:fs";
import path from "node:path";
import { themes as prismThemes } from "prism-react-renderer";
import type { Config } from "@docusaurus/types";
import type * as Preset from "@docusaurus/preset-classic";
import dotenv from "dotenv";
import remarkFixImagePaths from "./scripts/remark-fix-image-paths";
// Load environment variables from .env file
dotenv.config();
const docsRoot = path.join(__dirname, "docs");
const collectDocRouteInfo = (root: string) => {
const explicitSlugs = new Set<string>();
const docIds = new Set<string>();
const relativePaths = new Set<string>();
if (!fs.existsSync(root)) {
return { explicitSlugs, docIds, relativePaths };
}
const walk = (dir: string) => {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const entryPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
walk(entryPath);
continue;
}
if (!entry.name.endsWith(".md") && !entry.name.endsWith(".mdx")) {
continue;
}
const relativePath = path
.relative(root, entryPath)
.replace(/\\/g, "/")
.replace(/(index)?\.(md|mdx)$/i, "")
.replace(/(^\/|\/$)/g, "");
if (relativePath) {
relativePaths.add(relativePath);
}
try {
const content = fs.readFileSync(entryPath, "utf8");
if (content.startsWith("---")) {
const closingIndex = content.indexOf("---", 3);
if (closingIndex !== -1) {
const frontmatter = content.slice(3, closingIndex);
const slugMatch = frontmatter.match(
/^slug:\s*["']?(\/?[^"'\n]+)["']?/m
);
if (slugMatch?.[1]) {
const explicit = slugMatch[1].replace(/(^\/|\/$)/g, "").trim();
if (explicit) {
explicitSlugs.add(explicit);
}
}
const idMatch = frontmatter.match(/^id:\s*["']?([^"'\n]+)["']?/m);
if (idMatch?.[1]) {
const docId = idMatch[1].trim();
if (docId) {
docIds.add(docId);
}
} else if (relativePath) {
docIds.add(relativePath);
}
}
}
} catch (error) {
console.warn(
`[docusaurus] Unable to read doc frontmatter for ${entryPath}:`,
error
);
}
}
};
walk(root);
return { explicitSlugs, docIds, relativePaths };
};
const DOC_ROUTE_INFO = collectDocRouteInfo(docsRoot);
const ALL_DOC_PATHS = new Set<string>([
...DOC_ROUTE_INFO.explicitSlugs,
...DOC_ROUTE_INFO.docIds,
]);
const LOCALIZED_DOC_KEYS_BY_LOCALE = Object.fromEntries(
["pt", "es"].map((locale) => {
const localizedRouteInfo = collectDocRouteInfo(
path.join(
__dirname,
"i18n",
locale,
"docusaurus-plugin-content-docs",
"current"
)
);
return [
locale,
Array.from(
new Set([
...localizedRouteInfo.docIds,
...localizedRouteInfo.explicitSlugs,
...localizedRouteInfo.relativePaths,
])
).sort(),
];
})
);
const resolveDefaultDocsPage = (
value: string | undefined,
validSlugs: Set<string>
): string => {
const preferredFallbackCandidates = [
"overview",
"doc-overview",
"introduction",
"doc-introduction",
];
const preferredFallback =
preferredFallbackCandidates.find((candidate) =>
validSlugs.has(candidate)
) ??
Array.from(validSlugs)[0] ??
"overview";
const sanitize = (candidate?: string): string | undefined => {
if (!candidate) return undefined;
const trimmed = candidate.trim();
if (!trimmed) return undefined;
if (!/^[a-z0-9\-/]+$/i.test(trimmed)) {
console.warn(
`[docusaurus] DEFAULT_DOCS_PAGE="${trimmed}" contains invalid characters; ignoring.`
);
return undefined;
}
return trimmed.replace(/(^\/|\/$)/g, "");
};
const sanitized = sanitize(value);
if (sanitized && validSlugs.has(sanitized)) {
return sanitized;
}
if (sanitized && !validSlugs.has(sanitized)) {
console.warn(
`[docusaurus] DEFAULT_DOCS_PAGE="${sanitized}" not found under docs/. Falling back to "${preferredFallback}".`
);
}
return preferredFallback;
};
const DEFAULT_DOCS_PAGE = resolveDefaultDocsPage(
process.env.DEFAULT_DOCS_PAGE,
ALL_DOC_PATHS
);
// Determine if this is a production build (for SEO settings)
// Production allows indexing; staging/preview does not
const isProduction = process.env.IS_PRODUCTION === "true";
// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)
const config: Config = {
title: "Comapeo Documentation",
tagline: "Learn how to use the CoMapeo platform",
favicon: "img/favicon.ico",
// Custom fields to pass environment variables to client-side code
customFields: {
defaultDocsPage: DEFAULT_DOCS_PAGE,
localizedDocKeysByLocale: LOCALIZED_DOC_KEYS_BY_LOCALE,
},
// Set the production url of your site here
url: "https://docs.comapeo.app",
// Set the /<baseUrl>/ pathname under which your site is served
// For GitHub pages deployment, it is often '/<projectName>/'
baseUrl: process.env.BASE_URL || "/",
// GitHub pages deployment config.
// If you aren't using GitHub pages, you don't need these.
organizationName: "awana-digital", // Usually your GitHub org/user name.
projectName: "comapeo-docs", // Usually your repo name.
onBrokenLinks: "warn",
// Prevent search engines from indexing staging/preview builds
// Only production (IS_PRODUCTION=true) should be indexed
noIndex: !isProduction,
// Even if you don't use internationalization, you can use this field to set
// useful metadata like html lang. For example, if your site is Chinese, you
// may want to replace "en" with "zh-Hans".
i18n: {
defaultLocale: "en",
locales: ["en", "pt", "es"],
localeConfigs: {
en: {
label: "English",
htmlLang: "en-US",
},
pt: {
label: "Português",
htmlLang: "pt-BR",
},
es: {
label: "Español",
htmlLang: "es-ES",
},
},
},
markdown: {
hooks: {
onBrokenMarkdownLinks: "warn",
},
},
plugins: [
[
"@docusaurus/plugin-client-redirects",
{
redirects: [
// Redirect `/docs` and `/docs/` to default docs page (configurable via DEFAULT_DOCS_PAGE env var)
{
to: `/docs/${DEFAULT_DOCS_PAGE}`,
from: "/docs",
},
],
},
],
[
"@docusaurus/plugin-pwa",
{
debug: true,
offlineModeActivationStrategies: [
"appInstalled",
"standalone",
"queryString",
],
pwaHead: [
{
tagName: "link",
rel: "icon",
href: "/img/comapeo.png",
},
{
tagName: "link",
rel: "manifest",
href: "/manifest.json", // your PWA manifest
},
{
tagName: "meta",
name: "theme-color",
content: "#050F77",
},
],
},
],
[
"@docusaurus/plugin-ideal-image",
{
quality: 70,
max: 1030, // max resized image's size.
min: 640, // min resized image's size. if original is lower, use that size.
steps: 2, // the max number of images generated between min and max (inclusive)
disableInDev: false,
},
],
],
presets: [
[
"classic",
{
docs: {
path: "docs",
sidebarPath: "./src/components/sidebars.ts",
remarkPlugins: [remarkFixImagePaths],
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
editUrl:
"https://github.com/digidem/comapeo-docs/tree/main/packages/create-docusaurus/templates/shared/",
lastVersion: "current",
versions: {
current: {
label: "Latest",
},
},
},
theme: {
customCss: "./src/css/custom.css",
},
// Enable sitemap for production, disable for staging/preview
sitemap: isProduction
? {
lastmod: "date",
changefreq: "weekly",
priority: 0.5,
ignorePatterns: ["/tags/**"],
filename: "sitemap.xml",
}
: false,
} satisfies Preset.Options,
],
],
clientModules: [require.resolve("./src/client/scroll-to-top.ts")],
themeConfig: {
// Replace with your project's social card
image: "img/comapeo-social-card.jpg",
// Table of Contents configuration for consistent heading display
tableOfContents: {
minHeadingLevel: 2,
maxHeadingLevel: 3,
},
navbar: {
// title: 'CoMapeo',
logo: {
alt: "CoMapeo",
src: "img/comapeo_icon.png",
},
items: [
{
type: "docSidebar",
sidebarId: "docsSidebar",
position: "left",
label: "Documentation",
},
{
type: "docsVersionDropdown",
position: "left",
dropdownActiveClassDisabled: true,
},
{
type: "localeDropdown",
position: "right",
},
{
href: "https://github.com/digidem/comapeo-docs",
label: "GitHub",
position: "right",
},
],
},
footer: {
style: "dark",
links: [
{
title: "Awana Digital",
items: [
{
label: "Website",
href: "https://awana.digital",
},
{
label: "Discord",
href: "https://discord.gg/NtZgtAjj",
},
{
label: "Bluesky",
href: "https://bsky.app/profile/awana.digital",
},
{
label: "Blog",
href: "https://awana.digital/blog",
},
],
},
{
title: "CoMapeo",
items: [
{
label: "Website",
href: "https://comapeo.app",
},
{
label: "CoMapeo Mobile GitHub",
href: "https://github.com/digidem/comapeo-docs",
},
{
label: "CoMapeo Desktop GitHub",
href: "https://github.com/digidem/comapeo-docs",
},
],
},
{
title: "More",
items: [
{
label: "PlayStore",
href: "https://play.google.com/store/apps/details?id=com.comapeo",
},
{
label: "GitHub",
href: "https://github.com/digidem/comapeo-docs",
},
{
label: "Earth Defenders Toolkit",
href: "https://www.earthdefenderstoolkit.com/",
},
],
},
],
copyright: `Made with ❤️ by Awana Digital - ${new Date().getFullYear()}`,
},
prism: {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
},
} satisfies Preset.ThemeConfig,
};
export default config;