forked from nocobase/nocobase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.umirc.ts
130 lines (121 loc) · 2.89 KB
/
.umirc.ts
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
import transformer from '@umijs/preset-dumi/lib/transformer';
import { defineConfig } from 'dumi';
import fs from 'fs';
import path from 'path';
import menus from './docs/menus';
const lang = process.env.DOC_LANG || 'en-US';
console.log('process.env.DOC_LANG', process.env.DOC_LANG);
const findFilePath = (filename, lang) => {
const filePath = path.resolve(__dirname, `docs/${lang}/${filename}`);
if (fs.existsSync(`${filePath}.md`)) {
return `${filePath}.md`;
}
return;
};
const markdown = (filename, lang) => {
const filePath = findFilePath(filename, lang);
if (!filePath) {
return;
}
return transformer.markdown(fs.readFileSync(filePath, 'utf8').toString(), filePath);
};
const getPath = (value: string) => {
if (!value) {
return '';
}
const keys = value.split('/');
if (keys.pop() === 'index') {
return keys.join('/') || '/';
}
return value;
};
const getTitle = (item, lang) => {
if (lang) {
return item[`title.${lang}`] || item.title;
}
return item.title;
};
const parseMenuItems = (items: any[], lang: string) => {
const menuItems: any[] = [];
for (const item of items) {
if (typeof item === 'string') {
const result = markdown(item, lang);
if (result) {
menuItems.push({
title: result.meta.title,
disabled: result.meta.disabled,
path: getPath(item),
});
}
} else if (item.children) {
menuItems.push({
...item,
title: getTitle(item, lang),
children: parseMenuItems(item.children, lang),
});
} else if (item.path) {
menuItems.push({
...item,
title: getTitle(item, lang),
path: getPath(item.path),
});
} else {
menuItems.push({
title: getTitle(item, lang),
...item,
});
}
}
return menuItems;
};
const navs = [
{
title: 'Welcome',
'title.zh-CN': '欢迎',
path: '/welcome',
},
{
title: 'User manual',
'title.zh-CN': '使用手册',
path: '/manual',
},
{
title: 'Plugin Development',
'title.zh-CN': '插件开发',
path: '/development',
},
{
title: 'API reference',
'title.zh-CN': 'API 参考',
path: '/api',
},
{
title: 'Schema components',
'title.zh-CN': 'Schema 组件库',
path: '/components',
},
{
title: 'GitHub',
path: 'https://github.com/nocobase/nocobase',
},
];
export default defineConfig({
title: 'NocoBase',
outputPath: `./docs/dist/${lang}`,
mode: 'site',
resolve: {
includes: [`./docs/${lang}`],
},
locales: [[lang, lang]],
hash: true,
logo: 'https://www.nocobase.com/images/logo.png',
navs: {
'en-US': navs,
'zh-CN': navs.map((item) => ({ ...item, title: item['title.zh-CN'] || item.title })),
},
menus: Object.keys(menus).reduce((result, key) => {
const items = menus[key];
result[key] = parseMenuItems(items, lang);
return result;
}, {}),
});