-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rfct: migrate to vitepress-theme-project-trans
- Loading branch information
Showing
18 changed files
with
5,026 additions
and
4,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
/* eslint-disable */ | ||
/* prettier-ignore */ | ||
// @ts-nocheck | ||
// Generated by unplugin-vue-components | ||
// Read more: https://github.com/vuejs/core/pull/3399 | ||
export {} | ||
|
||
/* prettier-ignore */ | ||
declare module 'vue' { | ||
export interface GlobalComponents { | ||
Containers: typeof import('./theme/components/Containers.vue')['default'] | ||
HomeContent: typeof import('./theme/components/HomeContent.vue')['default'] | ||
PageInfo: typeof import('./theme/components/PageInfo.vue')['default'] | ||
RouterLink: typeof import('vue-router')['RouterLink'] | ||
RouterView: typeof import('vue-router')['RouterView'] | ||
Starport: typeof import('vue-starport')['Starport'] | ||
StarportCarrier: typeof import('vue-starport')['StarportCarrier'] | ||
AppearanceToggle: typeof import('./../../node_modules/.pnpm/@[email protected]_@[email protected]_@babel+parse_e5wfrc6b3bx3tagr3253ltif7q/node_modules/@project-trans/vitepress-theme-project-trans/dist/components/AppearanceToggle.vue')['default'] | ||
AppFooter: typeof import('./../../node_modules/.pnpm/@[email protected]_@[email protected]_@babel+parse_e5wfrc6b3bx3tagr3253ltif7q/node_modules/@project-trans/vitepress-theme-project-trans/dist/components/AppFooter.vue')['default'] | ||
AppSBox: typeof import('./../../node_modules/.pnpm/@[email protected]_@[email protected]_@babel+parse_e5wfrc6b3bx3tagr3253ltif7q/node_modules/@project-trans/vitepress-theme-project-trans/dist/components/AppSBox.vue')['default'] | ||
ArticlesMenu: typeof import('./../../node_modules/.pnpm/@[email protected]_@[email protected]_@babel+parse_e5wfrc6b3bx3tagr3253ltif7q/node_modules/@project-trans/vitepress-theme-project-trans/dist/components/ArticlesMenu.vue')['default'] | ||
CopyrightInfo: typeof import('./../../node_modules/.pnpm/@[email protected]_@[email protected]_@babel+parse_e5wfrc6b3bx3tagr3253ltif7q/node_modules/@project-trans/vitepress-theme-project-trans/dist/components/CopyrightInfo.vue')['default'] | ||
HomeContent: typeof import('./../../node_modules/.pnpm/@[email protected]_@[email protected]_@babel+parse_e5wfrc6b3bx3tagr3253ltif7q/node_modules/@project-trans/vitepress-theme-project-trans/dist/components/HomeContent.vue')['default'] | ||
PageInfo: typeof import('./../../node_modules/.pnpm/@[email protected]_@[email protected]_@babel+parse_e5wfrc6b3bx3tagr3253ltif7q/node_modules/@project-trans/vitepress-theme-project-trans/dist/components/PageInfo.vue')['default'] | ||
ReadingTime: typeof import('./../../node_modules/.pnpm/@[email protected]_@[email protected]_@babel+parse_e5wfrc6b3bx3tagr3253ltif7q/node_modules/@project-trans/vitepress-theme-project-trans/dist/components/ReadingTime.vue')['default'] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,168 +1,52 @@ | ||
import { readFileSync, statSync } from 'node:fs' | ||
import { join } from 'node:path' | ||
import { defineConfig } from 'vitepress' | ||
import mdPangu from 'markdown-it-pangu' | ||
import katex from 'markdown-it-katex' | ||
import footnote from 'markdown-it-footnote' | ||
import nav from './nav' | ||
import { sidebar } from './sidebar' | ||
|
||
const dir = 'docs' | ||
const siteTitle = 'SOC-8' | ||
|
||
// https://vitepress.dev/reference/site-config | ||
export default defineConfig({ | ||
lang: 'zh-CN', | ||
vite: { | ||
ssr: { | ||
noExternal: [ | ||
'@nolebase/vitepress-plugin-enhanced-readabilities', | ||
'@nolebase/vitepress-plugin-highlight-targeted-heading', | ||
], | ||
}, | ||
}, | ||
title: 'SOC-8', | ||
base: '/SOC-8/', | ||
markdown: { | ||
config(md) { | ||
md.use(mdPangu) | ||
md.use(footnote) | ||
md.use(katex) | ||
}, | ||
import genConfig from '@project-trans/vitepress-theme-project-trans/config' | ||
import type { SidebarOptions } from '@project-trans/vitepress-theme-project-trans/theme' | ||
import type { ThemeContext } from '@project-trans/vitepress-theme-project-trans/utils' | ||
import { withThemeContext } from '@project-trans/vitepress-theme-project-trans/utils' | ||
import type { DefaultTheme } from 'vitepress' | ||
|
||
type NavConfig = DefaultTheme.Config['nav'] | ||
|
||
const nav = [ | ||
{ | ||
text: '简体中文翻译', | ||
link: '/soc8cn/', | ||
}, | ||
dir, | ||
lastUpdated: true, | ||
head: [ | ||
['meta', { property: 'og:site_name', content: siteTitle }], | ||
], | ||
themeConfig: { | ||
// https://vitepress.dev/reference/default-theme-config | ||
siteTitle, | ||
nav, | ||
sidebar, | ||
|
||
socialLinks: [ | ||
{ icon: 'github', link: 'https://github.com/project-trans/SOC-8' }, | ||
], | ||
|
||
editLink: { | ||
pattern: 'https://github.com/project-trans/SOC-8/edit/main/docs/:path', | ||
text: '在 GitHub 上编辑此页面', // label localization | ||
}, | ||
|
||
// label localization | ||
outline: { label: '本页大纲', level: 'deep' }, | ||
lastUpdated: { text: '最后更新' }, | ||
darkModeSwitchLabel: '深色模式', | ||
sidebarMenuLabel: '目录', | ||
returnToTopLabel: '返回顶部', | ||
docFooter: { | ||
prev: '上一页', | ||
next: '下一页', | ||
}, | ||
}, | ||
transformHead: (context) => { | ||
const head = [...context.head] || [] | ||
|
||
const pageSourceFilePath = join(dir, context.pageData.filePath) | ||
const pageSourceFileStat = statSync(join(dir, context.pageData.filePath)) | ||
|
||
if (pageSourceFileStat.isDirectory()) { | ||
head.push([ | ||
'meta', | ||
{ | ||
property: 'og:title', | ||
content: siteTitle, | ||
}, | ||
]) | ||
|
||
head.push([ | ||
'meta', | ||
{ | ||
name: 'description', | ||
content: '跨性别和多元性别人群健康照护指南第八版(SOC-8)', | ||
}, | ||
]) | ||
|
||
return head | ||
} | ||
|
||
let pageSourceFileContent = readFileSync(pageSourceFilePath, { encoding: 'utf-8' }) | ||
] | ||
|
||
const baseConfig = { | ||
useTitleFromFrontmatter: true, | ||
sortMenusByFrontmatterOrder: true, | ||
useFolderTitleFromIndexFile: true, | ||
useFolderLinkFromIndexFile: true, | ||
excludeFilesByFrontmatterFieldName: true, | ||
collapsed: true, | ||
documentRootPath: '/docs', | ||
} satisfies Partial<SidebarOptions> | ||
|
||
const sidebarOptions = [ | ||
{ | ||
...baseConfig, | ||
scanStartPath: 'soc8cn', | ||
resolvePath: '/soc8cn/', | ||
sortMenusByFrontmatterOrder: true, | ||
} | ||
] | ||
|
||
const themeConfig: ThemeContext = { | ||
siteTitle: 'SOC-8', | ||
siteDescription: '跨性别和多元性别人群健康照护指南第八版(SOC-8)', | ||
baseUrl: '/SOC-8/', | ||
/** Repo */ | ||
githubRepoLink: 'https://github.com/project-trans/SOC-8', | ||
/** vitepress 根目录 */ | ||
rootDir: 'docs', | ||
/** 文档所在目录(目前似未使用此项) */ | ||
include: ['soc8cn'], | ||
nav, | ||
sidebarOptions, | ||
enableChangeLog: false, | ||
enableSuggestionBox: false, | ||
} | ||
|
||
// remove all frontmatter | ||
pageSourceFileContent = pageSourceFileContent.replace(/---[\s\S]*?---/, '') | ||
|
||
// remove markdown heading markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/^(#+)\s+(.*)/gm, ' $2 ') | ||
// remove markdown link markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/\[([^\]]+)\]\([^)]+\)/gm, ' $1 ') | ||
// remove markdown image markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/\!\[([^\]]+)\]\([^)]+\)/gm, ' $1 ') | ||
// remove markdown reference link markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/\[.*]/gm, '') | ||
// remove markdown bold markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/\*\*([^*]+)\*\*/gm, ' $1 ') | ||
pageSourceFileContent = pageSourceFileContent.replace(/__([^*]+)__/gm, ' $1 ') | ||
// remove markdown italic markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/\*([^*]+)\*/gm, ' $1 ') | ||
pageSourceFileContent = pageSourceFileContent.replace(/_([^*]+)_/gm, ' $1 ') | ||
// remove markdown code markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/`([^`]+)`/gm, ' $1 ') | ||
// remove markdown code block markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/```([^`]+)```/gm, ' $1 ') | ||
// remove markdown table header markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/\|:?-+:?\|/gm, '') | ||
// remove markdown table cell markup but keep the text content | ||
pageSourceFileContent = pageSourceFileContent.replace(/\|([^|]+)\|/gm, ' $1 ') | ||
|
||
// remove specific html tags completely | ||
const tags = [''] | ||
tags.forEach((tag) => { | ||
pageSourceFileContent = pageSourceFileContent.replace(new RegExp(`<${tag}[^>]*>[\\s\\S]*?<\\/${tag}>`, 'g'), '') | ||
}) | ||
|
||
// remove specific html tags but keep the text content | ||
const tagsToKeepContent = ['u', 'Containers', 'img', 'a'] | ||
tagsToKeepContent.forEach((tag) => { | ||
pageSourceFileContent = pageSourceFileContent.replace(new RegExp(`<${tag}[^>]*>([\\s\\S]*?)<\\/${tag}>`, 'g'), ' $1 ') | ||
}) | ||
|
||
// remove all new lines (either \r, \n) | ||
pageSourceFileContent = pageSourceFileContent.replace(/[\r|\n]/gm, '') | ||
|
||
// calculate the first 200 characters of the page content | ||
let pageContent = pageSourceFileContent.slice(0, 200) | ||
// trim space | ||
pageContent = pageContent.trim() | ||
// if pageSourceFileContent is longer than 200 characters, add ellipsis | ||
if (pageSourceFileContent.length > 100) | ||
pageContent += '...' | ||
|
||
head.push([ | ||
'meta', | ||
{ name: 'description', content: pageContent }, | ||
]) | ||
|
||
head.push([ | ||
'meta', | ||
{ property: 'og:title', content: context.title }, | ||
]) | ||
|
||
head.push([ | ||
'meta', | ||
{ property: 'og:description', content: pageContent }, | ||
]) | ||
|
||
head.push([ | ||
'meta', | ||
{ property: 'og:title', content: context.title }, | ||
]) | ||
|
||
head.push([ | ||
'meta', | ||
{ property: 'twitter:description', content: pageContent }, | ||
]) | ||
|
||
return head | ||
}, | ||
}) | ||
// https://vitepress.dev/reference/site-config | ||
export default withThemeContext(themeConfig, genConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.