Skip to content

Commit

Permalink
rfct: migrate to vitepress-theme-project-trans
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryolitia committed Sep 26, 2024
1 parent 7fb5673 commit 2ab70c8
Show file tree
Hide file tree
Showing 18 changed files with 5,026 additions and 4,065 deletions.
17 changes: 9 additions & 8 deletions docs/.vitepress/components.d.ts
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']
}
}
216 changes: 50 additions & 166 deletions docs/.vitepress/config.ts
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)
7 changes: 7 additions & 0 deletions docs/.vitepress/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ declare module 'markdown-it-pangu' {
const pangu: PluginSimple
export default pangu
}

declare module 'markdown-it-katex' {
import type { PluginSimple } from 'markdown-it'

const katex: PluginSimple
export default katex
}
9 changes: 0 additions & 9 deletions docs/.vitepress/nav.ts

This file was deleted.

33 changes: 0 additions & 33 deletions docs/.vitepress/plugins/markdownTransform.ts

This file was deleted.

15 changes: 0 additions & 15 deletions docs/.vitepress/sidebar.ts

This file was deleted.

9 changes: 0 additions & 9 deletions docs/.vitepress/theme/components/Containers.vue

This file was deleted.

56 changes: 0 additions & 56 deletions docs/.vitepress/theme/components/PageInfo.vue

This file was deleted.

Loading

0 comments on commit 2ab70c8

Please sign in to comment.