-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocusaurus.config.js
213 lines (202 loc) · 6.26 KB
/
docusaurus.config.js
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
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion
const fs = require("node:fs");
const path = require("node:path");
const lightCodeTheme = require("prism-react-renderer/themes/github");
const darkCodeTheme = require("prism-react-renderer/themes/dracula");
const DeployConfig = require("./deployConfig.js");
/** @param {...any} params */
const logger = (...params) => {
if (process.env.NODE_ENV === "production") {
console.log(...params);
}
};
const getDeployConfig = () => {
if (process.env.PLATFORM === "VERCEL") {
logger("===app build with: VERCEL===");
return DeployConfig.VERCEL;
}
if (process.env.PLATFORM === "NETLIFY") {
logger("===app build with: NETLIFY===");
return DeployConfig.NETLIFY;
}
logger("===app build with: GH_PAGES===");
return DeployConfig.GH_PAGES;
};
const getAllBlogRoutes = () => {
const workDir = process.cwd();
const rootPath = path.resolve(workDir, "blogs");
// 注意 `sort` 是 mutable 方法,会修改原数组
// 但是前面用了 `filter` 会返回一个新数组
return fs
.readdirSync(rootPath)
.filter((item) => !["authors.yml"].includes(item))
.sort((a, b) => Number(b) - Number(a));
};
const CUR_DEPLOY_ENV = getDeployConfig();
const blogRoutes = getAllBlogRoutes();
/** @type {import('@docusaurus/types').Config} */
const config = {
title: "Frontend Weekly",
tagline: "⭐️ 每周更新优质技术文章,欢迎点赞关注!",
url: "https://frontend-weekly.oss-cn-hangzhou.aliyuncs.com",
baseUrl: CUR_DEPLOY_ENV.baseUrl,
baseUrlIssueBanner: process.env.NODE_ENV !== "production",
// @ts-ignore
staticPath:
process.env.NODE_ENV === "production"
? "https://frontend-weekly.oss-cn-hangzhou.aliyuncs.com/"
: CUR_DEPLOY_ENV.baseUrl,
// baseUrl: "/",
onBrokenLinks: "throw",
onBrokenMarkdownLinks: "warn",
favicon: "img/favicon.ico",
organizationName: "facebook", // Usually your GitHub org/user name.
projectName: "docusaurus", // Usually your repo name.
plugins: [
...blogRoutes.map((item) => [
"@docusaurus/plugin-content-blog",
{
id: item,
routeBasePath: item,
path: `./blogs/${item}`,
authorsMapPath: "../authors.yml",
showReadingTime: true,
// Please change this to your repo.
editUrl:
"https://github.com/facebook/docusaurus/edit/main/website/blog/",
blogSidebarCount: "ALL",
blogSidebarTitle: `All posts in ${item}`,
},
]),
],
presets: [
[
"classic",
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: false,
// 不启用 preset 自带的博客功能
// 通过单独配置 plugin 启用
blog: false,
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
}),
],
],
customFields: {
blogRoutes,
},
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
// announcementBar: {
// id: 'announcementBar-2', // Increment on change
// content: `⭐️ <b>恭祝大家新春快乐,虎年大吉,虎虎生威!</b>`,
// },
// algolia: {
// appId: 'X1Z85QJPUV',
// apiKey: 'bf7211c161e8205da2f933a02534105a',
// indexName: 'docusaurus-2',
// contextualSearch: true,
// },
navbar: {
title: "Frontend Weekly",
logo: {
alt: "My Site Logo",
src: "img/logo.svg",
},
items: [
// { to: "/blog", label: "Blog", position: "left" },
{
type: "custom-doc-version-navbar-item",
position: "right",
items: blogRoutes.map((item) => ({
to: item,
label: item,
})),
},
// {
// type: 'dropdown',
// label: '技术交流群',
// position: 'right',
// items: [
// {
// href: 'https://github.com/garfield-dev-team/frontend-weekly/tree/main/static/img/IMG_0058.JPG',
// label: '⭐️ 前端交流群',
// },
// {
// href: 'https://github.com/garfield-dev-team/frontend-weekly/tree/main/static/img/IMG_0058.JPG',
// label: '🌛 云居山茶室',
// },
// ]
// },
{
href: "https://github.com/garfield-dev-team/frontend-weekly/tree/main/static/img/IMG_0058.JPG",
label: "⭐️ 前端交流群",
position: "right",
},
{
href: "https://github.com/garfield-dev-team/frontend-weekly",
label: "GitHub",
position: "right",
},
],
},
footer: {
style: "dark",
links: [
{
title: "Blog",
items: [
{
label: "Tutorial",
to: `/${blogRoutes.at(0)}`,
},
],
},
{
title: "Community",
items: [
{
label: "Garfield-cli 前端工程化",
href: "https://github.com/garfield-dev-team/Garfield-cli",
},
{
label: "NPM 工程化规范",
href: "https://github.com/Jiacheng787/Garfield-utils",
},
{
label: "React 从零到一工程化指北",
href: "https://github.com/Jiacheng787/React-zero-to-one",
},
],
},
{
title: "More",
items: [
{
label: "Golang 学习",
href: "https://github.com/Jiacheng787/go-by-example",
},
{
label: "面试内容汇总",
href: "https://github.com/Jiacheng787/Bytedance-interview",
},
],
},
],
copyright:
`Copyright © ${new Date().getFullYear()} Garfield Dev Team.` +
" Built with Docusaurus." +
` Deploys on ${CUR_DEPLOY_ENV.platform}.`,
},
prism: {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
additionalLanguages: ["java"],
},
}),
};
module.exports = config;