-
Notifications
You must be signed in to change notification settings - Fork 258
Expand file tree
/
Copy pathdocusaurus.config.js
More file actions
762 lines (703 loc) · 23.7 KB
/
docusaurus.config.js
File metadata and controls
762 lines (703 loc) · 23.7 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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion
const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
const path = require('path');
// 从 frontmatter 中提取 aliases
function getFrontmatterAliases() {
try {
const fs = require('fs');
const path = require('path');
const glob = require('glob');
// ====== 1) 只在本地 dev server 跳过(更可靠的判断) ======
// Docusaurus 在 start/build/deploy 的环境变量有时会被工具链改写,
// 所以不要再单纯依赖 NODE_ENV/BABEL_ENV。
// 这里用一个更稳的策略:如果是交互式 dev server(start)才跳过扫描。
const argv = process.argv.join(' ');
const isStartCommand = /\bdocusaurus\b.*\bstart\b/.test(argv) || /\bstart\b/.test(argv);
if (isStartCommand) {
return [];
}
const docsDir = path.join(__dirname, 'docs');
const docsExists = fs.existsSync(docsDir);
if (!docsExists) {
console.warn('警告: docs 目录不存在,跳过 aliases 处理');
return [];
}
// ====== 2) 扫描所有 md/mdx ======
const files = glob.sync(path.join(docsDir, '**/*.{md,mdx}'), {
windowsPathsNoEscape: true,
dot: false,
nodir: true,
});
if (files.length === 0) {
console.warn('警告: 没有找到任何文档文件');
return [];
}
// ====== 3) 更稳的 frontmatter 匹配(兼容 BOM / CRLF / 前置空行) ======
const FM_RE = /^\uFEFF?\s*---\s*\r?\n([\s\S]*?)\r?\n---/;
/** @param {string} p */
const normPath = (p) => {
if (!p) return '/';
let x = p.trim();
x = x.startsWith('/') ? x : `/${x}`;
x = x.replace(/\/{2,}/g, '/');
return x;
};
/** @param {string} p */
const withSlash = (p) => (p.endsWith('/') ? p : `${p}/`);
// ====== 4) 先收集所有真实页面路径(slug 或文件路径)用于 to 校验 ======
const existingPaths = new Set();
for (const filePath of files) {
try {
const content = fs.readFileSync(filePath, 'utf8');
const fm = content.match(FM_RE);
if (!fm) continue;
const frontmatterText = fm[1];
const slugMatch = frontmatterText.match(/slug:\s*['"]?([^'"\n\r]+)['"]?/);
/** @type {string} */
let target;
if (slugMatch) {
target = normPath(slugMatch[1]);
} else {
const relativePath = path.relative(docsDir, filePath);
const docPath = relativePath.replace(/\.(md|mdx)$/, '').replace(/\\/g, '/');
target = normPath(docPath);
}
existingPaths.add(target);
existingPaths.add(withSlash(target));
} catch {
// ignore single file errors
}
}
// ====== 5) 生成 redirects(from 去重 + 只生成带 / 的 from) ======
/** @type {{from: string; to: string}[]} */
const redirects = [];
const seenFrom = new Set();
let processedDocsWithAliases = 0;
let aliasFrontmatterFiles = 0;
let skippedCount = 0;
let dedupedCount = 0;
for (const filePath of files) {
try {
const content = fs.readFileSync(filePath, 'utf8');
const fm = content.match(FM_RE);
if (!fm) continue;
const frontmatterText = fm[1];
if (!frontmatterText.includes('aliases:')) continue;
aliasFrontmatterFiles++;
const slugMatch = frontmatterText.match(/slug:\s*['"]?([^'"\n\r]+)['"]?/);
/** @type {string[]} */
let aliases = [];
// 形式 1:aliases: ["/a", "/b"]
const bracketMatch = frontmatterText.match(/aliases:\s*\[(.*?)\]/s);
if (bracketMatch) {
aliases = bracketMatch[1]
.split(',')
.map((a) => a.trim().replace(/['"]/g, ''))
.filter(Boolean);
} else {
// 形式 2:YAML list
const yamlMatch = frontmatterText.match(/aliases:\s*\r?\n((?:\s*-\s*.+\r?\n?)*)/);
if (yamlMatch) {
aliases = yamlMatch[1]
.split(/\r?\n/)
.map((line) => {
const m = line.match(/^\s*-\s*(.+)$/);
return m ? m[1].trim().replace(/['"]/g, '') : '';
})
.filter(Boolean);
}
}
if (aliases.length === 0) continue;
// 目标路径(统一带 /)
/** @type {string} */
let targetPath;
if (slugMatch) {
targetPath = normPath(slugMatch[1]);
} else {
const relativePath = path.relative(docsDir, filePath);
const docPath = relativePath.replace(/\.(md|mdx)$/, '').replace(/\\/g, '/');
targetPath = normPath(docPath);
}
const to = withSlash(targetPath);
// to 校验:存在任意一种就认为有效
if (!existingPaths.has(targetPath) && !existingPaths.has(to)) {
skippedCount++;
continue;
}
// from:只生成带 / 的版本(避免 trailingSlash 下落盘冲突)
for (const alias of aliases) {
const from = withSlash(normPath(alias));
if (seenFrom.has(from)) {
dedupedCount++;
continue;
}
seenFrom.add(from);
redirects.push({ from, to });
}
processedDocsWithAliases++;
} catch (/** @type {any} */ error) {
console.warn(`警告: 处理文件 ${filePath} 时出错: ${error.message}`);
}
}
console.log(
`🔗 从 ${processedDocsWithAliases} 个文档中创建 ${redirects.length} 个有效的 aliases 重定向(去重丢弃 ${dedupedCount} 条)`,
);
if (skippedCount > 0) {
console.log(`⚠️ 跳过了 ${skippedCount} 个无效的目标路径`);
}
return redirects;
} catch (/** @type {any} */ error) {
console.error('处理 frontmatter aliases 时出错:', error.message);
return [];
}
}
// Wrap the entire config in an async IIFE
module.exports = (async () => {
// Dynamically import ESM modules
const remarkMath = (await import('remark-math')).default;
const rehypeKatex = (await import('rehype-katex')).default;
/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'Seeed Studio Wiki',
tagline:
'The Seeed Studio Files Management Platform, Opening up and Cooperation.',
url: 'https://wiki.seeedstudio.com',
baseUrl: '/',
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'ignore',
onBrokenAnchors: 'ignore',
favicon: 'img/S.png',
themes: ['docusaurus-theme-search-typesense'],
scripts: [
// String format.
// 'https://viewer.altium.com/client/static/js/embed.js',
// Object format.
{
src: 'https://viewer.altium.com/client/static/js/embed.js',
async: true,
},
{
src: '/js/custom.js', // 添加你的 JavaScript 文件名、
async: true,
},
{
src: '/js/language-switcher.js',
async: true,
},
],
future: {
v4: true, // Enable future Docusaurus v4 features
experimental_faster: true, // Enable experimental faster features
},
// GitHub pages deployment config.
// If you aren't using GitHub pages, you don't need these.
organizationName: 'Seeed-Studio', // Usually your GitHub org/user name.
projectName: 'wiki-documents', // Usually your repo name.
trailingSlash: true,
// Even if you don't use internalization, 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'],
path: 'i18n',
localeConfigs: {
en: {
label: 'English',
direction: 'ltr',
htmlLang: 'en-US',
calendar: 'gregory',
path: 'en',
},
},
},
presets: [
[
'classic',
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
path: 'docs',
routeBasePath: '/',
sidebarPath: require.resolve('./sidebars.js'),
// 先保留 last update(你需要)
showLastUpdateAuthor: true,
showLastUpdateTime: true,
// 先保留数学插件(你原来就有)
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeKatex],
// Edit link 先保持正确
editUrl: 'https://github.com/Seeed-Studio/wiki-documents/blob/docusaurus-version/sites/en/docs/',
},
googleTagManager: {
containerId: 'GTM-M4JG2HVB',
},
// blog: {
// showReadingTime: true,
// // Please change this to your repo.
// // Remove this to remove the "edit this page" links.
// editUrl:
// 'https://github.com/Seeed-Studio/wiki-documents/blob/docusaurus-version/',
// },
theme: {
customCss: require.resolve('./src/css/custom.css'),
},
pages: {
path: 'src/pages',
routeBasePath: '/',
include: ['**/*.{js,jsx,ts,tsx,md,mdx}'],
exclude: [
'cn/**',
'zh-CN/**',
'ja/**',
'es/**',
'pt-br/**',
],
},
}),
],
],
plugins: [
// [
// '@docusaurus/plugin-pwa',
// {
// debug: true,
// offlineModeActivationStrategies: [
// 'appInstalled',
// 'standalone',
// 'queryString',
// ],
// pwaHead: [
// {
// tagName: 'link',
// rel: 'icon',
// href: '/img/S.png',
// },
// {
// tagName: 'link',
// rel: 'manifest',
// href: '/manifest.json', // your PWA manifest
// },
// {
// tagName: 'meta',
// name: 'theme-color',
// content: 'rgb(37, 194, 160)',
// },
// ],
// },
// ],
function webpackAliasPlugin() {
return {
name: 'webpack-alias-assets',
configureWebpack() {
return {
resolve: {
alias: {
'@assets': path.resolve(__dirname, '../../assets'),
},
},
};
},
};
},
// 添加 frontmatter aliases 重定向插件
[
'@docusaurus/plugin-client-redirects',
(() => {
const redirects = getFrontmatterAliases();
return { redirects };
})(),
],
'docusaurus-plugin-image-zoom',
'docusaurus-plugin-sass',
],
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
zoom: {
selector: '.markdown :not(em) > img',
background: {
dark: 'rgb(50, 50, 50)',
light: 'rgb(255, 255, 255)',
},
// zoom: { // This seems to be a duplicate key "zoom", perhaps meant for medium-zoom options?
// selector: '.markdown :not(a) > img', // Exclude images inside links
// },
// The options for docusaurus-plugin-image-zoom are usually directly under the plugin's key in themeConfig, not nested again under "zoom"
// Check the plugin's documentation. If the inner zoom is for medium-zoom options, it should be under 'config'
config: { // This is the correct place for medium-zoom options
// selector: '.markdown :not(a) > img', // If you want to override default selector for zoom behavior
},
},
colorMode: {
defaultMode: 'dark',
// disableSwitch: true,
},
tableOfContents: {
minHeadingLevel: 2,
maxHeadingLevel: 5,
},
giscus: {
repo: 'Seeed-Studio/wiki-documents',
repoId: 'MDEwOlJlcG9zaXRvcnkzMDM5NTk0Nzk=',
category: 'Q&A',
categoryId: 'DIC_kwDOEh4Nt84CTIbM',
theme: 'light_high_contrast',
darkTheme: 'dark_tritanopia',
},
docs: {
sidebar: {
hideable: true,
autoCollapseCategories: true,
},
},
navbar: {
// title: 'My Site',
logo: {
alt: 'Seeed Studio',
src:
'https://files.seeedstudio.com/wiki/wiki-platform/SeeedStudio.png',
srcDark:
'https://files.seeedstudio.com/wiki/wiki-platform/seeed_white_logo.png',
href: '/',
className: 'navbar_logo_items',
},
items: [
{
label: 'Quick Links',
to: '/Getting_Started',
position: 'left',
className: 'navbar_dorp_items js_getting_started',
items: [
{
label: 'Sensor and Sensing',
to: 'Sensor_Network',
},
{
label: 'Networking',
to: 'Network',
},
{
label: 'Edge Computing',
to: 'Edge_Computing',
},
{
label: 'Cloud',
to: 'Cloud',
},
],
},
{
label: 'Explore with Topics',
to: '/topicintroduction',
position: 'left',
className: 'navbar_dorp_items js_explore_learn',
items: [
{
label: 'TinyML',
to: '/tinyml_topic',
},
{
label: 'SenseCraft Model Assistant',
to: '/ModelAssistant_Introduce_Overview',
},
{
label: 'Home Assistant',
to: '/home_assistant_topic',
},
{
label: 'Open Source',
to: '/open_source_topic',
},
{
label: 'Edge AI',
to: '/edge_ai_topic',
},
{
label: 'Wiki 矽递科技 (中文)',
to: 'https://wiki.seeedstudio.com/cn/Getting_Started',
},
{
label: 'Wiki SeeedStudio (日本語)',
to: 'https://wiki.seeedstudio.com/ja/Getting_Started',
},
{
label: 'Wiki SeeedStudio (Español)',
to: 'https://wiki.seeedstudio.com/es/Getting_Started',
},
],
},
{
type: 'dropdown',
label: 'FAQs',
to: '/knowledgebase',
position: 'left',
className: 'navbar_dorp_items',
items: [
{
label: 'NVIDIA Jetson Series',
to: '/Jetson_FAQ',
},
{
label: 'Seeed Studio XIAO Series',
to: '/XIAO_FAQ',
},
{
label: 'reComputer R1000 Series',
to: '/reComputer_R1000_FAQ',
},
{
label: 'reTerminal',
to: '/reTerminal-new_FAQ',
},
{
label: 'reRouter',
to: '/FAQs_For_openWrt',
},
{
label: 'Odyssey',
to: '/ODYSSEY_FAQ',
},
{
label: 'Wio Terminal',
to: '/wio_terminal_faq',
},
{
type: 'html',
value: '<hr style="margin: 8px 0;">',
},
{
label: 'Discord',
href: 'https://discord.com/invite/eWkprNDMU7',
},
{
label: 'Email',
href: 'https://www.seeedstudio.com/contacts',
},
{
label: 'Forum',
href: 'https://forum.seeedstudio.com/',
},
{
label: 'Have Suggestions?',
href:
'https://github.com/Seeed-Studio/wiki-documents/discussions/69',
},
],
},
{
type: 'dropdown',
label: 'Get Involved',
to: 'https://www.seeedstudio.com/ranger-program',
position: 'left',
className: 'navbar_dorp_items',
items: [
{
label: 'Affiliate & Creator',
to: 'https://www.seeedstudio.com/blog/affiliate-program/',
},
{
label: 'Rangers',
to: 'https://www.seeedstudio.com/ranger-program/',
},
{
label: 'Contributors',
to: '/contributors',
},
{
label: 'Apply for Rangers',
href:
'https://docs.google.com/forms/d/e/1FAIpQLSdiAWHmRJqgVNTJyJDkzhufc1dygFyhWFyEtUTm-mrgSKaEgg/viewform',
},
{
label: 'Direct to Assignments',
href: 'https://github.com/orgs/Seeed-Studio/projects/6',
},
{
label: 'More about Rangers',
href:
'https://www.seeedstudio.com/blog/2023/09/15/join-the-seeed-ranger-program-empowering-developers-and-building-communities/',
},
{
label: 'More about Contributors',
href: 'https://wiki.seeedstudio.com/Contributor',
},
],
},
{
to: 'https://www.seeedstudio.com/',
label: 'Bazaar 🛍️',
position: 'right',
className: 'navbar_doc_right_items',
},
{
to: 'https://sensecraft.seeed.cc/ai/#/home',
label: 'SenseCraft AI',
position: 'right',
className: 'navbar_doc_right_items',
},
{
href: 'https://sensecraft.seeed.cc/ai/#/home',
position: 'right',
className: 'header-SSCMA',
},
{
href: 'https://github.com/Seeed-Studio/wiki-documents',
position: 'right',
className: 'header-github-link',
'aria-label': 'GitHub repository',
},
],
},
footer: {
style: 'dark',
links: [
{
title: 'Navigation',
items: [
{
label: 'Getting Started',
to: '/Getting_Started',
},
{
label: 'Sensor and Sensing',
to: '/Sensor_Network',
},
{
label: 'Network',
to: '/Network',
},
{
label: 'Edge Computing',
to: '/Edge_Computing',
},
{
label: 'Cloud',
to: '/Cloud',
},
{
label: 'Solutions',
to: 'https://solution.seeed.cc/',
},
],
},
{
title: 'Ecosystem',
items: [
{
label: 'Discord',
to: 'https://discord.com/invite/QqMgVwHT3X',
},
{
label: 'Project Hub',
to: 'https://project.seeedstudio.com/',
},
{
label: 'Partners',
to: 'https://www.seeedstudio.com/ecosystem/',
},
{
label: 'Distributors',
to: 'https://www.seeedstudio.com/distributors.html',
},
],
},
{
title: 'Quick Guide',
items: [
{
label: 'Bazaar',
to: 'https://www.seeedstudio.com/',
},
{
label: 'How to get help',
to: 'https://www.seeedstudio.com/get_help/HowToGetHelp',
},
{
label: 'FAQs',
to: 'https://support.seeedstudio.com/knowledgebase',
},
{
label: 'Forum',
to: 'https://forum.seeedstudio.com/',
},
{
label: 'Technical Support',
to: 'https://www.seeedstudio.com/get_help/TechnicalSupport',
},
],
},
{
title: 'Company',
items: [
{
label: 'About Seeed',
to: 'https://www.seeedstudio.com/about-us/',
},
{
label: 'Join us',
to: 'https://www.seeedstudio.com/join-us/',
},
{
label: 'Contact Us',
to: 'https://www.seeedstudio.com/contacts',
},
{
label: 'Press',
to:
'https://www.seeedstudio.com/blog/2020/04/22/seeed-in-the-news/',
},
],
},
],
copyright: `Copyright © ${new Date().getFullYear()} Seeed Studio, Inc. Built with Docusaurus.`,
},
prism: {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
additionalLanguages: ['bash'],
},
contextualSearch: true,
typesense: {
typesenseCollectionName: 'wiki_platform_test_1767765204',
typesenseServerConfig: {
nodes: [
{
host: 'search.seeedstudio.com',
protocol: 'https',
},
],
apiKey: 'z1DHV8drOZizrn9TSlf0U9QgNENgBxGR',
},
typesenseSearchParameters: {
query_by: 'hierarchy.lvl0,hierarchy.lvl2,content,sku_tag',
},
transformSearchParameters: (
/** @type {string} */ inputString,
/** @type {Record<string, unknown>} */ searchParameters,
) => {
if (/^\d{5,}$/.test(inputString)) {
console.log('检测到 SKU 搜索:', inputString);
return {
...searchParameters,
query_by: 'sku_tag',
query: inputString,
// filter_by: 'doc_type_tag:=gettingstarted && !doc_type_tag:=project',
};
}
return searchParameters;
},
},
announcementBar: {
id: 'support_us',
content: '<span id="announcement-text">Collaborate with Seeed - <a target="_blank" href="https://www.seeedstudio.com/blog/affiliate-program/">Creator</a>, <a target="_blank" href="https://www.seeedstudio.com/ranger-program/">Ranger</a>, or <a target="_blank" href="https://wiki.seeedstudio.com/contributors/">Contributor</a>, there is always a role ideal for you!</span>',
backgroundColor: '#013949',
textColor: '#FFFFFF',
isCloseable: false,
},
}),
};
return config; // Return the config object from the IIFE
})();