-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodern.config.ts
104 lines (99 loc) · 2.91 KB
/
modern.config.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
import { defineConfig, docTools } from '@modern-js/doc-tools';
import path from 'path';
const isProd = () => process.env.NODE_ENV === 'production';
function getI18nHelper(lang: 'zh' | 'en') {
const cn = lang === 'zh';
// 默认语言为中文,如果是英文,需要加上 /en 前缀
// The default language is Chinese, if it is English, you need to add the /en prefix
const prefix = cn ? '' : '/en';
const getLink = (str: string) => `${prefix}${str}`;
const getText = (cnText: string, enText: string) => (cn ? cnText : enText);
return { getText, getLink };
}
function getNavConfig(lang: 'zh' | 'en') {
const { getText, getLink } = getI18nHelper(lang);
return [
{
text: getText('首页', 'Home'),
link: getLink('/'),
},
];
}
function getSidebarConfig(lang: 'zh' | 'en') {
const { getText, getLink } = getI18nHelper(lang);
// 注: 侧边栏配置可以嵌套,子菜单字段为 items
// Note: The sidebar configuration can be nested, and the sub-menu field is items
return {
[getLink('/guide')]: [
{
collapsed: false,
collapsible: false,
text: getText('开始', 'Getting Started'),
items: [getLink('/guide/introduction')],
},
{
collapsed: false,
collapsible: false,
text: getText('网络协议', 'http'),
items: [getLink('/guide/http/http')],
},
{
text: getText('Javascript相关', 'javascript'),
items: [
getLink('/guide/javascript/javascript'),
getLink('/guide/ES6/Decorator'),
getLink('/guide/ES6/Promise'),
],
},
{
text: getText('手写代码', 'write-code'),
link: getLink('/guide/write-code/write-code'),
},
],
};
}
export default defineConfig({
doc: {
// https://modernjs.dev/doc-tools/zh/api/config/config-basic.html
base: isProd() ? '/Front-End-Interview/' : '/',
root: path.join(__dirname, 'docs'),
head: [
`
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?08dd1a00b1e317cd0a730370a212193a";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
`,
],
// 默认语言
// Default language
lang: 'zh',
themeConfig: {
footer: {
// 页脚的文案
// Footer text
message: '© 2023 JavaSwing Reserved.',
},
// 不同语言的配置
// Configuration for different languages
locales: [
{
lang: 'zh',
title: '前端面试手册',
description: '前端面试手册',
// nav: getNavConfig('zh'),
sidebar: getSidebarConfig('zh'),
// 语言切换按钮的文案
// Language switch button text
label: '简体中文',
},
],
},
},
plugins: [docTools()],
});