Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 优化 vitepress 配置 #34

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions .vitepress/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'
import sidebarData from './gitbooktoc'
import gtagConfig from './gtag'
import { tokenize } from './search'

const urlBase = process.env.URL_BASE || undefined

Expand All @@ -18,7 +19,7 @@ export default {
rel: 'icon',
type: 'image/png',
sizes: '32x32',
href: path.join(urlBase || '', 'favicon.png')
href: path.join(urlBase || '/', 'favicon.png')
}
],
...gtagConfig
Expand All @@ -40,29 +41,59 @@ export default {
rewrites: {
'HOME.md': 'index.md',
'README.md': 'introduction.md',
':a*/README.md': ':a*/index.md',
':a*/:b*/README.md': ':a*/:b*/index.md',
':a*/:b*/:c*/README.md': ':a*/:b*/:c*/index.md'
':z/:a/README.md': ':a/index.md',
':z/:a/:b/README.md': ':a/:b/index.md',
':z/:a/:b*': ':a/:b*'
},
themeConfig: {
logo: 'favicon.png',
outline: 'deep',
outlineTitle: '大纲',
returnToTopLabel: '返回顶部',
sidebarMenuLabel: '目录',
docFooter: {
prev: '上一页',
next: '下一页'
},
editLink: {
pattern: 'https://github.com/2ndLA/English/edit/main/:path',
text: 'Edit this page on GitHub'
text: 'GitHub 上编辑此页'
},
footer: {
message: '🇨🇳 🇬🇧 Second-language Acquisition',
copyright: '© 2023-present <a href="https://github.com/2ndLA" target="_blank">2ndLA Team</a>. <a href="https://github.com/2ndLA/English/blob/main/LICENSE" target="_blank">CC BY-NC-SA 4.0</a>.'
},
lastUpdated: {
text: '更新于',
formatOptions: {
dateStyle: 'medium',
timeStyle: 'short'
}
},
nav: [
{ text: '🗺️ 2ndLA', link: 'https://github.com/2ndLA' }
],
search: {
provider: 'local',
options: {
detailedView: true,
miniSearch: {
// https://lucaong.github.io/minisearch/modules/MiniSearch.html
options: {
tokenize
},
searchOptions: {
fuzzy: 0.1,
prefix: true,
boost: {
title: 4,
text: 2
},
combineWith: 'AND'
}
}
}
},
sidebar: sidebarData,
socialLinks: [
{ icon: 'github', link: 'https://github.com/2ndLA/English' }
Expand Down
23 changes: 16 additions & 7 deletions .vitepress/gitbooktoc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { readFileSync } from 'fs'

const PATTERN = /^ *\* \[(?<title>.*)\]\((?<path>.*)\.md\)$/
const REGEX = {
TOC: /^ *\* \[(?<title>.*)\]\((?<path>.*)\.md\)$/,
INDEX: /README$/,
CONTENT: /content\//
}

const SPECIAL_PATH = {
README: '/README',
INTRO: '/introduction'
}

class Node {
constructor(title, path) {
Expand All @@ -24,9 +33,9 @@ class Node {
toJSON() {
return {
text: this.text,
link: this.link === '/README'
? '/introduction'
: this.link.replace(/README$/, ''),
link: this.link === SPECIAL_PATH.README
? SPECIAL_PATH.INTRO
: this.link.replace(REGEX.INDEX, '').replace(REGEX.CONTENT, ''),
collapsed: this.collapsed,
items: this.items.length > 0 ? this.items : undefined
}
Expand All @@ -35,7 +44,7 @@ class Node {

function constructNode(line, result) {
if (line.startsWith('*')) {
const match = line.match(PATTERN)
const match = line.match(REGEX.TOC)
const { title, path } = match.groups
result.push(new Node(title, path))
return result
Expand All @@ -57,7 +66,7 @@ function sidebar(lines, result = []) {
function readGitBookSidebar() {
const gbSidebarContent = readFileSync('SUMMARY.md')
const gbSidebarLines = gbSidebarContent.toString().split('\n')
const filteredGbSidebarLines = gbSidebarLines.filter(line => PATTERN.test(line))
const filteredGbSidebarLines = gbSidebarLines.filter(line => REGEX.TOC.test(line))
const sidebarData = sidebar(filteredGbSidebarLines, [])
return sidebarData
}
Expand All @@ -70,4 +79,4 @@ try {
process.exit(1)
}

export default result
export default JSON.parse(JSON.stringify(result))
14 changes: 14 additions & 0 deletions .vitepress/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions .vitepress/theme/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
--gb-c-blue-darker: #183267;
/* GitBook Colors */

--vp-c-brand: var(--gb-c-blue);
--vp-c-brand-light: var(--gb-c-bluegray-light);
--vp-c-brand-lighter: var(--gb-c-bluegray-lighter);
--vp-c-brand-dark: var(--gb-c-blue-dark);
--vp-c-brand-darker: var(--gb-c-blue-darker);
--vp-c-brand-1: var(--gb-c-blue);
--vp-c-brand-2: var(--gb-c-blue-dark);
--vp-c-brand-3: var(--gb-c-blue);
--vp-c-brand-soft: var(--gb-c-bluegray-lighter);
}

/* Text Theme */
.vp-doc a {
text-decoration: none;
}

/* CheckList Customization */
Expand Down
2 changes: 1 addition & 1 deletion HOME.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ hero:
text: 开始阅读
link: /introduction
- theme: alt
text: GitHub 项目
text: GitHub 仓库
link: https://github.com/2ndLA/English

features:
Expand Down
2 changes: 1 addition & 1 deletion content/primer/duolingo.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ App 的内购价格比较昂贵,并且需要绑定支付(Android 上是绑
12. ***in*** the party (党派)
13. ***in/on*** a team

关于介词更详尽的使用方法,请查看「[📓 语法](/content/grammar/)」部分。
关于介词更详尽的使用方法,请查看「[📓 语法](/grammar/)」部分。
2 changes: 1 addition & 1 deletion content/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Chrome 扩展商店需要科学上网才能访问,你可以考虑使用其他

这类英汉词典非常多,选主流厂商的即可,比如网易的「[有道词典](https://dict.youdao.com/)」、微软的「[必应词典](https://cn.bing.com/dict)」。这些词典一般都有**网页版**(建议加到浏览器书签栏)和**移动端** ,通常还具备段落级别的英汉互译功能。

如果你对词典页面的音标、词性标注感兴趣,请查看「[🔠 词汇](/content/vocabulary/)」部分。
如果你对词典页面的音标、词性标注感兴趣,请查看「[🔠 词汇](/vocabulary/)」部分。

#### 段落翻译

Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-promise": "^6.1.1",
"flexsearch": "^0.7.31",
"husky": "^8.0.3",
"markdown-it-task-checkbox": "^1.0.6",
"vite": "^4.1.4",
"vitepress": "^1.0.0-alpha.46",
"vitepress-plugin-search": "^1.0.4-alpha.19",
"vue": "^3.2.47"
"vitepress": "^1.0.0-rc.20"
}
}
11 changes: 0 additions & 11 deletions vite.config.js

This file was deleted.

Loading
Loading