-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodern.config.ts
118 lines (113 loc) · 3.41 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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('书本', 'book'),
items: [
getLink('/guide/book/chap3'),
getLink('/guide/book/chap4'),
getLink('/guide/book/chap5'),
getLink('/guide/book/chap6'),
getLink('/guide/book/chap7'),
getLink('/guide/book/chap8'),
getLink('/guide/book/recursive'),
getLink('/guide/book/heap'),
getLink('/guide/book/chap13'),
getLink('/guide/book/chap14'),
getLink('/guide/book/dynamicProgramming'),
],
},
{
text: getText('二进制', 'system'),
link: getLink('/guide/system'),
},
{
text: getText('技巧', 'skill'),
link: getLink('/guide/other'),
},
],
};
}
export default defineConfig({
doc: {
// https://modernjs.dev/doc-tools/zh/api/config/config-basic.html
base: isProd() ? '/leet-code/' : '/',
root: path.join(__dirname, 'docs'),
head: [
`<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?08a989582e08d8cc546189a487b20fc9";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
`,
],
// 默认语言
// Default language
lang: 'zh',
themeConfig: {
footer: {
// 页脚的文案
// Footer text
message: '© 2023 JavaSwing Reserved.',
},
socialLinks: [
{
icon: 'github',
mode: 'link',
content: 'https://github.com/javaswing/leet-code',
},
],
// 不同语言的配置
// Configuration for different languages
locales: [
{
lang: 'zh',
title: '数据结构与算法学习笔记',
description: 'JavaScript数据结构与算法及对应LeetCode题代码',
// nav: getNavConfig('zh'),
sidebar: getSidebarConfig('zh'),
// 语言切换按钮的文案
// Language switch button text
label: '简体中文',
},
],
},
},
plugins: [docTools()],
});