From c0c52e29b02056f600fd6340a0b6c2841c4d2878 Mon Sep 17 00:00:00 2001 From: Northword Date: Sun, 30 Jun 2024 20:21:35 +0800 Subject: [PATCH] feat: convert absolute link to relative link and fix types error --- .vitepress/config/markdown.config.ts | 2 +- .vitepress/plugins/markdownTransform.ts | 36 ++++++++++++++++++++----- src/wiki | 2 +- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.vitepress/config/markdown.config.ts b/.vitepress/config/markdown.config.ts index 2e10905..6dd9baa 100644 --- a/.vitepress/config/markdown.config.ts +++ b/.vitepress/config/markdown.config.ts @@ -4,7 +4,7 @@ import { mark } from '@mdit/plugin-mark' import { markdown as _markdown } from '../../src/wiki/.vitepress/config/markdown' export const markdown: UserConfig['markdown'] = { - ..._markdown, + ..._markdown as Omit, config: (md) => { md.use(footnote) md.use(mark) diff --git a/.vitepress/plugins/markdownTransform.ts b/.vitepress/plugins/markdownTransform.ts index 5dff567..1a8ecb8 100644 --- a/.vitepress/plugins/markdownTransform.ts +++ b/.vitepress/plugins/markdownTransform.ts @@ -5,6 +5,8 @@ export function MarkdownTransform(): Plugin { name: 'zotero-chinese-md-transform', enforce: 'pre', async transform(code, id) { + // id 为文件磁盘绝对路径 + if (!id.match(/\.md\b/)) return null @@ -13,16 +15,38 @@ export function MarkdownTransform(): Plugin { /https?:\/\/zotero-chinese\.com\/user-guide\//g, '/user-guide/', ) + code = code.replaceAll( + /https?:\/\/zotero-chinese\.com\/plugins\/?/g, + '/plugins/', + ) + code = code.replaceAll( + /https?:\/\/zotero-chinese\.com\/styles\/?/g, + '/styles/', + ) + code = code.replaceAll( + /https?:\/\/zotero-chinese\.com\//g, + '/', + ) + + // wiki 部分贡献指南 + if (id.match('/wiki/')) { + // code = [ + // code, + // '', + // ].join('\n\n') + } // CSL 样式部分 if (id.match(/styles\/detail\/.*\.md/)) { // 为详情页增加 md 前言 - code = `--- -sidebar: false -comments: false -editLink: false ---- -${code}` + code = [ + '---', + 'sidebar: false', + 'comments: false', + 'editLink: false', + '---', + code, + ].join('\n') // CSL 详情页的头部块 code = code.replace( diff --git a/src/wiki b/src/wiki index c69545e..8258fad 160000 --- a/src/wiki +++ b/src/wiki @@ -1 +1 @@ -Subproject commit c69545e01adc095199d1f74345f806a309422c36 +Subproject commit 8258fada0ee54157e058bc01acd0b0f46f53e244