Skip to content

Commit d0ad54c

Browse files
committed
refactor: multi-language support - zh-CN
1 parent 1cd9de4 commit d0ad54c

File tree

966 files changed

+190
-175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

966 files changed

+190
-175
lines changed

.vitepress/config.ts

Lines changed: 86 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import MarkdownItFootnote from 'markdown-it-footnote'
1010
import MarkdownItMathjax3 from 'markdown-it-mathjax3'
1111
import { defineConfig } from 'vitepress'
1212

13-
import { creatorNames, creatorUsernames, discordLink, githubRepoLink, siteDescription, siteName, targetDomain } from '../metadata'
13+
import { discordLink, githubRepoLink, siteDescription, siteName } from '../metadata'
14+
import head from './head'
1415

1516
export default defineConfig({
1617
vue: {
@@ -25,198 +26,110 @@ export default defineConfig({
2526
},
2627
},
2728
},
28-
lang: 'zh-CN',
2929
title: siteName,
3030
description: siteDescription,
3131
ignoreDeadLinks: true,
32-
head: [
33-
['meta', {
34-
name: 'theme-color',
35-
content: '#ffffff',
36-
}],
37-
[
38-
'link',
39-
{
40-
rel: 'apple-touch-icon',
41-
href: '/apple-touch-icon.png',
42-
sizes: '180x180',
43-
},
44-
],
45-
['link', {
46-
rel: 'icon',
47-
href: '/logo.svg',
48-
type: 'image/svg+xml',
49-
}],
50-
[
51-
'link',
52-
{
53-
rel: 'alternate icon',
54-
href: '/favicon.ico',
55-
type: 'image/png',
56-
sizes: '16x16',
57-
},
58-
],
59-
['meta', {
60-
name: 'author',
61-
content: creatorNames.join(', '),
62-
}],
63-
[
64-
'meta',
65-
{
66-
name: 'keywords',
67-
content:
68-
['markdown', 'knowledge-base', '知识库', 'vitepress', 'obsidian', 'notebook', 'notes', ...creatorUsernames].join(', '),
69-
},
70-
],
71-
72-
['meta', {
73-
property: 'og:title',
74-
content: siteName,
75-
}],
76-
[
77-
'meta',
78-
{
79-
property: 'og:image',
80-
content: `${targetDomain}/og.png`,
81-
},
82-
],
83-
['meta', {
84-
property: 'og:description',
85-
content: siteDescription,
86-
}],
87-
['meta', {
88-
property: 'og:site_name',
89-
content: siteName,
90-
}],
91-
92-
['meta', {
93-
name: 'twitter:card',
94-
content: 'summary_large_image',
95-
}],
96-
['meta', {
97-
name: 'twitter:creator',
98-
content: creatorUsernames.join(', '),
99-
}],
100-
[
101-
'meta',
102-
{
103-
name: 'twitter:image',
104-
content: `${targetDomain}/og.png`,
105-
},
106-
],
107-
108-
[
109-
'link',
110-
{
111-
rel: 'mask-icon',
112-
href: '/safari-pinned-tab.svg',
113-
color: '#927baf',
114-
},
115-
],
116-
['link', {
117-
rel: 'manifest',
118-
href: '/site.webmanifest',
119-
}],
120-
['meta', {
121-
name: 'msapplication-TileColor',
122-
content: '#603cba',
123-
}],
124-
// Proxying Plausible through Netlify | Plausible docs
125-
// https://plausible.io/docs/proxy/guides/netlify
126-
['script', { 'defer': 'true', 'data-domain': 'nolebase.ayaka.io', 'data-api': '/api/v1/page-external-data/submit', 'src': '/assets/page-external-data/js/script.js' }],
127-
],
128-
themeConfig: {
129-
outline: { label: '页面大纲', level: 'deep' },
130-
darkModeSwitchLabel: '切换主题',
131-
editLink: {
132-
pattern: `${githubRepoLink}/tree/main/:path`,
133-
text: '编辑本页面',
134-
},
135-
socialLinks: [
136-
{ icon: 'github', link: githubRepoLink },
137-
{ icon: 'discord', link: discordLink },
138-
],
139-
footer: {
140-
message: '用 <span style="color: #e25555;">&#9829;</span> 撰写',
141-
copyright:
32+
head,
33+
locales: {
34+
root: {
35+
lang: 'zh-CN',
36+
label: '中文',
37+
dir: '/zh-CN',
38+
link: '/zh-CN',
39+
themeConfig: {
40+
nav: [
41+
{ text: '主页', link: '/zh-CN/' },
42+
{ text: '笔记', link: '/zh-CN/笔记/' },
43+
{ text: '编目 Catalog', link: '/zh-CN/编目 Catalog/' },
44+
{ text: '最近更新', link: '/zh-CN/toc' },
45+
],
46+
socialLinks: [
47+
{ icon: 'github', link: githubRepoLink },
48+
{ icon: 'discord', link: discordLink },
49+
],
50+
darkModeSwitchLabel: '切换主题',
51+
outline: { label: '页面大纲', level: 'deep' },
52+
editLink: {
53+
pattern: `${githubRepoLink}/tree/main/:path`,
54+
text: '编辑本页面',
55+
},
56+
sidebar: calculateSidebar([
57+
{ folderName: 'zh-CN/笔记', separate: true },
58+
{ folderName: 'zh-CN/编目 Catalog', separate: true },
59+
], 'zh-CN'),
60+
footer: {
61+
message: '用 <span style="color: #e25555;">&#9829;</span> 撰写',
62+
copyright:
14263
'<a class="footer-cc-link" target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a> © 2022-PRESENT Nólëbase 的创作者们',
143-
},
144-
search: {
145-
provider: 'local',
146-
options: {
147-
locales: {
148-
root: {
149-
translations: {
150-
button: {
151-
buttonText: '搜索文档',
152-
buttonAriaLabel: '搜索文档',
153-
},
154-
modal: {
155-
noResultsText: '无法找到相关结果',
156-
resetButtonTitle: '清除查询条件',
157-
footer: {
158-
selectText: '选择',
159-
navigateText: '切换',
64+
},
65+
search: {
66+
provider: 'local',
67+
options: {
68+
locales: {
69+
root: {
70+
translations: {
71+
button: {
72+
buttonText: '搜索文档',
73+
buttonAriaLabel: '搜索文档',
74+
},
75+
modal: {
76+
noResultsText: '无法找到相关结果',
77+
resetButtonTitle: '清除查询条件',
78+
footer: {
79+
selectText: '选择',
80+
navigateText: '切换',
81+
},
82+
},
16083
},
16184
},
16285
},
163-
},
164-
},
16586

166-
// Add title ang tags field in frontmatter to search
167-
// You can exclude a page from search by adding search: false to the page's frontmatter.
168-
_render(src, env, md) {
169-
// without `md.render(src, env)`, the some information will be missing from the env.
170-
let html = md.render(src, env)
171-
let tagsPart = ''
172-
let headingPart = ''
173-
let contentPart = ''
174-
let fullContent = ''
175-
const sortContent = () => [headingPart, tagsPart, contentPart] as const
176-
let { frontmatter, content } = env
87+
// Add title ang tags field in frontmatter to search
88+
// You can exclude a page from search by adding search: false to the page's frontmatter.
89+
_render(src, env, md) {
90+
// without `md.render(src, env)`, the some information will be missing from the env.
91+
let html = md.render(src, env)
92+
let tagsPart = ''
93+
let headingPart = ''
94+
let contentPart = ''
95+
let fullContent = ''
96+
const sortContent = () => [headingPart, tagsPart, contentPart] as const
97+
let { frontmatter, content } = env
17798

178-
if (!frontmatter)
179-
return html
99+
if (!frontmatter)
100+
return html
180101

181-
if (frontmatter.search === false)
182-
return ''
102+
if (frontmatter.search === false)
103+
return ''
183104

184-
contentPart = content ||= src
105+
contentPart = content ||= src
185106

186-
const headingMatch = content.match(/^# .*/m)
187-
const hasHeading = !!(headingMatch && headingMatch[0] && headingMatch.index !== undefined)
107+
const headingMatch = content.match(/^# .*/m)
108+
const hasHeading = !!(headingMatch && headingMatch[0] && headingMatch.index !== undefined)
188109

189-
if (hasHeading) {
190-
const headingEnd = headingMatch.index! + headingMatch[0].length
191-
headingPart = content.slice(0, headingEnd)
192-
contentPart = content.slice(headingEnd)
193-
}
194-
else if (frontmatter.title) {
195-
headingPart = `# ${frontmatter.title}`
196-
}
110+
if (hasHeading) {
111+
const headingEnd = headingMatch.index! + headingMatch[0].length
112+
headingPart = content.slice(0, headingEnd)
113+
contentPart = content.slice(headingEnd)
114+
}
115+
else if (frontmatter.title) {
116+
headingPart = `# ${frontmatter.title}`
117+
}
197118

198-
const tags = frontmatter.tags
199-
if (tags && Array.isArray(tags) && tags.length)
200-
tagsPart = `Tags: #${tags.join(', #')}`
119+
const tags = frontmatter.tags
120+
if (tags && Array.isArray(tags) && tags.length)
121+
tagsPart = `Tags: #${tags.join(', #')}`
201122

202-
fullContent = sortContent().filter(Boolean).join('\n\n')
123+
fullContent = sortContent().filter(Boolean).join('\n\n')
203124

204-
html = md.render(fullContent, env)
125+
html = md.render(fullContent, env)
205126

206-
return html
127+
return html
128+
},
129+
},
207130
},
208131
},
209132
},
210-
nav: [
211-
{ text: '主页', link: '/' },
212-
{ text: '笔记', link: '/笔记/' },
213-
{ text: '编目 Catalog', link: '/编目 Catalog/' },
214-
{ text: '最近更新', link: '/toc' },
215-
],
216-
sidebar: calculateSidebar([
217-
{ folderName: '笔记', separate: true },
218-
{ folderName: '编目 Catalog', separate: true },
219-
]),
220133
},
221134
markdown: {
222135
theme: {

.vitepress/head.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import type { HeadConfig } from 'vitepress'
2+
import { creatorNames, creatorUsernames, siteDescription, siteName, targetDomain } from '../metadata'
3+
4+
export default [
5+
['meta', {
6+
name: 'theme-color',
7+
content: '#ffffff',
8+
}],
9+
[
10+
'link',
11+
{
12+
rel: 'apple-touch-icon',
13+
href: '/apple-touch-icon.png',
14+
sizes: '180x180',
15+
},
16+
],
17+
[
18+
'link',
19+
{
20+
rel: 'icon',
21+
href: '/logo.svg',
22+
type: 'image/svg+xml',
23+
},
24+
],
25+
[
26+
'link',
27+
{
28+
rel: 'alternate icon',
29+
href: '/favicon.ico',
30+
type: 'image/png',
31+
sizes: '16x16',
32+
},
33+
],
34+
['meta', {
35+
name: 'author',
36+
content: creatorNames.join(', '),
37+
}],
38+
[
39+
'meta',
40+
{
41+
name: 'keywords',
42+
content:
43+
['markdown', 'knowledge-base', '知识库', 'vitepress', 'obsidian', 'notebook', 'notes', ...creatorUsernames].join(', '),
44+
},
45+
],
46+
47+
['meta', {
48+
property: 'og:title',
49+
content: siteName,
50+
}],
51+
[
52+
'meta',
53+
{
54+
property: 'og:image',
55+
content: `${targetDomain}/og.png`,
56+
},
57+
],
58+
['meta', {
59+
property: 'og:description',
60+
content: siteDescription,
61+
}],
62+
['meta', {
63+
property: 'og:site_name',
64+
content: siteName,
65+
}],
66+
67+
['meta', {
68+
name: 'twitter:card',
69+
content: 'summary_large_image',
70+
}],
71+
['meta', {
72+
name: 'twitter:creator',
73+
content: creatorUsernames.join(', '),
74+
}],
75+
[
76+
'meta',
77+
{
78+
name: 'twitter:image',
79+
content: `${targetDomain}/og.png`,
80+
},
81+
],
82+
83+
[
84+
'link',
85+
{
86+
rel: 'mask-icon',
87+
href: '/safari-pinned-tab.svg',
88+
color: '#927baf',
89+
},
90+
],
91+
['link', {
92+
rel: 'manifest',
93+
href: '/site.webmanifest',
94+
}],
95+
['meta', {
96+
name: 'msapplication-TileColor',
97+
content: '#603cba',
98+
}],
99+
// Proxying Plausible through Netlify | Plausible docs
100+
// https://plausible.io/docs/proxy/guides/netlify
101+
['script', { 'defer': 'true', 'data-domain': 'nolebase.ayaka.io', 'data-api': '/api/v1/page-external-data/submit', 'src': '/assets/page-external-data/js/script.js' }],
102+
] satisfies HeadConfig[]

0 commit comments

Comments
 (0)