diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index ea65704..2f783e5 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -8,12 +8,12 @@ import { rootDir, githubRepoLink } from './meta' import { readFileSync, statSync } from 'node:fs' import { join } from 'node:path' const siteTitle = 'RLE.wiki' +const siteDescription = '一份 RLE 指北' // https://vitepress.dev/reference/site-config export default defineConfig({ lang: 'zh-CN', - title: 'RLE.wiki', - description: '一份 RLE 指北', + title: siteTitle, cleanUrls: true, markdown: { config(md) { @@ -30,7 +30,6 @@ export default defineConfig({ ['link', { rel: "manifest", href: "/site.webmanifest" }], ['meta', { name: "msapplication-TileColor", content: "#4c4c4c" }], ['meta', { name: "theme-color", content: "#ffffff" }], - ['meta', { property: 'og:title', content: siteTitle }], ['meta', { property: 'og:site_name', content: siteTitle }], ], themeConfig: { @@ -99,6 +98,22 @@ export default defineConfig({ const pageSourceFileStat = statSync(join(rootDir, context.pageData.filePath)) if (pageSourceFileStat.isDirectory()) { + head.push([ + 'meta', + { + property: 'og:title', + content: siteTitle, + }, + ]) + + head.push([ + 'meta', + { + name: 'description', + content: '跨性别和多元性别人群健康照护指南第八版(SOC-8)', + }, + ]) + return head } @@ -108,25 +123,27 @@ export default defineConfig({ pageSourceFileContent = pageSourceFileContent.replace(/---[\s\S]*?---/, '') // remove markdown heading markup but keep the text content - pageSourceFileContent = pageSourceFileContent.replace(/^(#+)\s+(.*)/gm, '$2') + pageSourceFileContent = pageSourceFileContent.replace(/^(#+)\s+(.*)/gm, ' $2 ') // remove markdown link markup but keep the text content - pageSourceFileContent = pageSourceFileContent.replace(/\[([^\]]+)\]\([^)]+\)/gm, '$1') + pageSourceFileContent = pageSourceFileContent.replace(/\[([^\]]+)\]\([^)]+\)/gm, ' $1 ') // remove markdown image markup but keep the text content - pageSourceFileContent = pageSourceFileContent.replace(/\!\[([^\]]+)\]\([^)]+\)/gm, '$1') + 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') + 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') + pageSourceFileContent = pageSourceFileContent.replace(/\*([^*]+)\*/gm, ' $1 ') + pageSourceFileContent = pageSourceFileContent.replace(/_([^*]+)_/gm, ' $1 ') // remove markdown code markup but keep the text content - pageSourceFileContent = pageSourceFileContent.replace(/`([^`]+)`/gm, '$1') + pageSourceFileContent = pageSourceFileContent.replace(/`([^`]+)`/gm, ' $1 ') // remove markdown code block markup but keep the text content - pageSourceFileContent = pageSourceFileContent.replace(/```([^`]+)```/gm, '$1') + pageSourceFileContent = pageSourceFileContent.replace(/```([^`]+)```/gm, ' $1 ') // remove markdown table header markup but keep the text content - pageSourceFileContent = pageSourceFileContent.replace(/\|:?-+:?\|/gm, '|') + pageSourceFileContent = pageSourceFileContent.replace(/\|:?-+:?\|/gm, '') // remove markdown table cell markup but keep the text content - pageSourceFileContent = pageSourceFileContent.replace(/\|([^|]+)\|/gm, '$1') + pageSourceFileContent = pageSourceFileContent.replace(/\|([^|]+)\|/gm, ' $1 ') // remove specific html tags completely const tags = [''] @@ -137,7 +154,7 @@ export default defineConfig({ // 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') + pageSourceFileContent = pageSourceFileContent.replace(new RegExp(`<${tag}[^>]*>([\\s\\S]*?)<\\/${tag}>`, 'g'), ' $1 ') }) // remove all new lines (either \r, \n) @@ -145,20 +162,35 @@ export default defineConfig({ // 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 > 200) { + if (pageSourceFileContent.length > 100) pageContent += '...' - } - // add the page content as meta description head.push([ 'meta', - { name: 'description', content: pageContent } + { name: 'description', content: pageContent }, ]) head.push([ 'meta', - { property: 'og:description', content: pageContent } + { 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