Skip to content

Commit fd32f07

Browse files
Merge branch 'main' into release/2.9.8
2 parents 08e2251 + 9f46c98 commit fd32f07

37 files changed

+2712
-1375
lines changed

.github/workflows/deploy.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Deploy to Gitee
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
15+
- name: Install pnpm
16+
uses: pnpm/action-setup@v2
17+
with:
18+
version: 6
19+
20+
- name: Set node version to 16.x
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: 16.x
24+
registry-url: https://registry.npmjs.org/
25+
cache: "pnpm"
26+
27+
- name: Install deps
28+
run: pnpm install
29+
30+
- run: pnpm run build
31+
- run: |
32+
cd .vitepress/dist
33+
git init
34+
git config user.email "[email protected]"
35+
git config user.name "Evan You"
36+
git add .
37+
git commit -m "update docs"
38+
git remote add origin https://yyx990803:${{ secrets.GITEE_TOKEN }}@gitee.com/vuejs-cn/vite-docs-cn.git
39+
git push origin HEAD:master --force

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
Thumbs.db
3+
db.json
4+
*.log
5+
node_modules/
6+
.deploy*/
7+
package-lock.json
8+
yarn.lock
9+
.vitepress/dist
10+
*.local

.vitepress/config.js

+46-37
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
// @ts-check
22

3+
const pkg = require('../package.json')
4+
35
/**
46
* @type {import('vitepress').UserConfig}
57
*/
68
module.exports = {
7-
title: 'Vite',
8-
description: 'Next Generation Frontend Tooling',
9-
head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]],
9+
title: 'Vite 官方中文文档',
10+
lang: 'zh-CN',
11+
description: '下一代前端开发与构建工具',
12+
head: [
13+
['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }],
14+
['script', { src: 'https://cdn.wwads.cn/js/makemoney.js', async: '' }]
15+
],
1016
vue: {
1117
reactivityTransform: true
1218
},
1319
themeConfig: {
14-
repo: 'vitejs/vite',
20+
repo: pkg.repository,
1521
logo: '/logo.svg',
16-
docsDir: 'docs',
1722
docsBranch: 'main',
1823
editLinks: true,
19-
editLinkText: 'Suggest changes to this page',
24+
editLinkText: '为此页提供修改建议',
2025

2126
algolia: {
2227
apiKey: 'b573aa848fd57fb47d693b531297403c',
2328
indexName: 'vitejs',
2429
searchParameters: {
25-
facetFilters: ['tags:en']
30+
facetFilters: ['tags:cn']
2631
}
2732
},
2833

29-
carbonAds: {
30-
carbon: 'CEBIEK3N',
31-
placement: 'vitejsdev'
32-
},
33-
3434
nav: [
35-
{ text: 'Guide', link: '/guide/' },
36-
{ text: 'Config', link: '/config/' },
37-
{ text: 'Plugins', link: '/plugins/' },
35+
{ text: '指引', link: '/guide/' },
36+
{ text: '配置', link: '/config/' },
37+
{ text: '插件', link: '/plugins/' },
3838
{
39-
text: 'Links',
39+
text: '相关链接',
4040
items: [
4141
{
4242
text: 'Twitter',
@@ -51,21 +51,21 @@ module.exports = {
5151
link: 'https://github.com/vitejs/awesome-vite'
5252
},
5353
{
54-
text: 'DEV Community',
54+
text: 'Dev.to 社区',
5555
link: 'https://dev.to/t/vite'
5656
},
5757
{
58-
text: 'Rollup Plugins Compat',
58+
text: 'Rollup 插件兼容',
5959
link: 'https://vite-rollup-plugins.patak.dev/'
6060
},
6161
{
62-
text: 'Changelog',
62+
text: '更新日志',
6363
link: 'https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md'
6464
}
6565
]
6666
},
6767
{
68-
text: 'Languages',
68+
text: '多语言',
6969
items: [
7070
{
7171
text: 'English',
@@ -89,67 +89,67 @@ module.exports = {
8989
// catch-all fallback
9090
'/': [
9191
{
92-
text: 'Guide',
92+
text: '指引',
9393
children: [
9494
{
95-
text: 'Why Vite',
95+
text: '为什么选 Vite',
9696
link: '/guide/why'
9797
},
9898
{
99-
text: 'Getting Started',
99+
text: '开始',
100100
link: '/guide/'
101101
},
102102
{
103-
text: 'Features',
103+
text: '功能',
104104
link: '/guide/features'
105105
},
106106
{
107-
text: 'Using Plugins',
107+
text: '使用插件',
108108
link: '/guide/using-plugins'
109109
},
110110
{
111-
text: 'Dependency Pre-Bundling',
111+
text: '依赖预构建',
112112
link: '/guide/dep-pre-bundling'
113113
},
114114
{
115-
text: 'Static Asset Handling',
115+
text: '静态资源处理',
116116
link: '/guide/assets'
117117
},
118118
{
119-
text: 'Building for Production',
119+
text: '构建生产版本',
120120
link: '/guide/build'
121121
},
122122
{
123-
text: 'Deploying a Static Site',
123+
text: '部署静态站点',
124124
link: '/guide/static-deploy'
125125
},
126126
{
127-
text: 'Env Variables and Modes',
127+
text: '环境变量与模式',
128128
link: '/guide/env-and-mode'
129129
},
130130
{
131-
text: 'Server-Side Rendering (SSR)',
131+
text: '服务端渲染(SSR',
132132
link: '/guide/ssr'
133133
},
134134
{
135-
text: 'Backend Integration',
135+
text: '后端集成',
136136
link: '/guide/backend-integration'
137137
},
138138
{
139-
text: 'Comparisons',
139+
text: '比较',
140140
link: '/guide/comparisons'
141141
},
142142
{
143-
text: 'Migration from v1',
143+
text: '从 v1 迁移',
144144
link: '/guide/migration'
145145
}
146146
]
147147
},
148148
{
149-
text: 'APIs',
149+
text: 'API',
150150
children: [
151151
{
152-
text: 'Plugin API',
152+
text: '插件 API',
153153
link: '/guide/api-plugin'
154154
},
155155
{
@@ -161,12 +161,21 @@ module.exports = {
161161
link: '/guide/api-javascript'
162162
},
163163
{
164-
text: 'Config Reference',
164+
text: '配置参考',
165165
link: '/config/'
166166
}
167167
]
168168
}
169169
]
170170
}
171+
},
172+
173+
markdown: {
174+
anchor: {
175+
renderPermalink: require('./render-perma-link')
176+
},
177+
config: (md) => {
178+
md.use(require('./markdown-it-custom-anchor'))
179+
}
171180
}
172181
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const anchorMatch = /^.+(\s*\{#([a-z0-9\-_]+?)\}\s*)$/;
2+
3+
const removeAnchorFromTitle = (oldTitle) => {
4+
const match = anchorMatch.exec(oldTitle);
5+
return match ? oldTitle.replace(match[1], '').trim() : oldTitle;
6+
}
7+
8+
module.exports = function plugin(md) {
9+
const oldTitle = md.renderer.rules.text;
10+
md.renderer.rules.text = (tokens, idx, options, env, slf) => {
11+
const titleAndId = oldTitle(tokens, idx, options, env, slf);
12+
return removeAnchorFromTitle(titleAndId);
13+
};
14+
15+
const oldHeading = md.renderer.rules.heading_open;
16+
md.renderer.rules.heading_open = (tokens, idx, options, env, slf) => {
17+
const head = oldHeading(tokens, idx, options, env, slf);
18+
const data = md.__data;
19+
const headers = data.headers || (data.headers = []);
20+
headers.forEach(element => {
21+
element.title = removeAnchorFromTitle(element.title);
22+
});
23+
return head;
24+
}
25+
};

.vitepress/render-perma-link/index.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const position = {
2+
false: 'push',
3+
true: 'unshift'
4+
}
5+
6+
const renderPermalink = (slug, opts, state, permalink) => {
7+
try {
8+
const tokens = state.tokens
9+
const token = tokens[permalink]
10+
const title = tokens[permalink + 1]
11+
.children
12+
.filter(token => token.type === 'text' || token.type === 'code_inline')
13+
.reduce((acc, t) => acc + t.content, '')
14+
const match = /^.+(\s*\{#([a-z0-9\-_]+?)\}\s*)$/.exec(title);
15+
slug = match ? match[2] : slug;
16+
token.attrSet('id', slug)
17+
const space = () => Object.assign(new state.Token('text', '', 0), { content: ' ' })
18+
19+
const linkTokens = [
20+
Object.assign(new state.Token('link_open', 'a', 1), {
21+
attrs: [
22+
...(opts.permalinkClass ? [['class', opts.permalinkClass]] : []),
23+
['href', opts.permalinkHref(slug, state)],
24+
...Object.entries(opts.permalinkAttrs(slug, state))
25+
]
26+
}),
27+
Object.assign(new state.Token('html_block', '', 0), { content: opts.permalinkSymbol }),
28+
new state.Token('link_close', 'a', -1)
29+
]
30+
if (opts.permalinkSpace) {
31+
linkTokens[position[!opts.permalinkBefore]](space())
32+
}
33+
state.tokens[permalink + 1].children[position[opts.permalinkBefore]](...linkTokens)
34+
} catch(e) {}
35+
}
36+
37+
module.exports = renderPermalink

.vitepress/rewrite-title/index.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const path = require('path')
2+
const fsp = require('fs').promises
3+
const matterService = require('../utils/frontmatter-service')
4+
const workspacePath = path.resolve(__dirname, '..', '..')
5+
6+
const h1MdRegExp = /^#\s+(.+)\s+(\{#([\w-]+)\})$/
7+
/** 在此书写所有文章所在的目录名 */
8+
const articleDirs = ['blog', 'config', 'guide', 'plugins']
9+
10+
const rewriteMarkdownTitle = (filePath) => {
11+
const matter = matterService.open(filePath)
12+
const lines = String(matter.file).split(/\r?\n/)
13+
const h1Line = lines.find((line) => h1MdRegExp.test(line))
14+
if (!h1Line) return
15+
16+
const title = h1MdRegExp.exec(h1Line)[1]
17+
matter.set('title', title).save()
18+
}
19+
20+
const ergodicDirectory = async (dirPath) => {
21+
try {
22+
const files = await fsp.readdir(dirPath)
23+
for (let i = 0; i < files.length; i++) {
24+
const file = files[i],
25+
filePath = path.join(dirPath, file)
26+
const stats = await fsp.stat(filePath)
27+
if (stats.isFile()) {
28+
if (filePath.split('.').pop().toLowerCase() === 'md') {
29+
rewriteMarkdownTitle(filePath)
30+
}
31+
} else if (stats.isDirectory()) {
32+
if (articleDirs.includes(filePath.split('/').pop())) {
33+
await ergodicDirectory(filePath)
34+
}
35+
}
36+
}
37+
} catch (err) {
38+
console.warn(
39+
`vite-docs-cn: failed to rewrite frontmatter for titles.\n ${err}!`
40+
)
41+
}
42+
}
43+
44+
module.exports = () => ergodicDirectory(workspacePath)

0 commit comments

Comments
 (0)