diff --git a/docs/.vitepress/markdownAssets.test.ts b/docs/.vitepress/markdownAssets.test.ts new file mode 100644 index 0000000..2323d4e --- /dev/null +++ b/docs/.vitepress/markdownAssets.test.ts @@ -0,0 +1,52 @@ +import { existsSync, readdirSync, readFileSync } from "node:fs"; +import { dirname, join, relative, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import { describe, expect, it } from "vitest"; + +const docsRoot = fileURLToPath(new URL("../", import.meta.url)); +const markdownImage = /!\[[^\]]*\]\(([^)]+)\)/g; + +const findMarkdownFiles = (directory: string): string[] => + readdirSync(directory, { withFileTypes: true }).flatMap((entry) => { + const path = join(directory, entry.name); + + if (entry.isDirectory()) return findMarkdownFiles(path); + return entry.isFile() && entry.name.endsWith(".md") ? [path] : []; + }); + +const isExternalAsset = (href: string) => + href.startsWith("#") || + href.startsWith("/") || + href.startsWith("//") || + /^[a-z][a-z\d+.-]*:/i.test(href); + +describe("Markdown image assets", () => { + it("uses valid POSIX paths that resolve to local files", () => { + const invalidAssets: string[] = []; + + for (const markdownFile of findMarkdownFiles(docsRoot)) { + const content = readFileSync(markdownFile, "utf8"); + + for (const match of content.matchAll(markdownImage)) { + const href = match[1].trim(); + if (isExternalAsset(href)) continue; + + const source = `${relative(docsRoot, markdownFile)} → ${href}`; + if (href.includes("\\")) { + invalidAssets.push(`${source} (use / instead of \\)`); + continue; + } + + const assetPath = resolve( + dirname(markdownFile), + decodeURIComponent(href), + ); + if (!existsSync(assetPath)) { + invalidAssets.push(`${source} (file not found)`); + } + } + } + + expect(invalidAssets).toEqual([]); + }); +}); diff --git a/docs/cases/submissions/wechat-ima-knowledge/index.md b/docs/cases/submissions/wechat-ima-knowledge/index.md index 44a875e..ace1a1b 100644 --- a/docs/cases/submissions/wechat-ima-knowledge/index.md +++ b/docs/cases/submissions/wechat-ima-knowledge/index.md @@ -76,13 +76,13 @@ ima 知识库连接器是 WorkBuddy 与 ima 之间的桥梁——WorkBuddy 可 - **图片/截图**:长按图片 → 用小程序打开 → 选择 ima 日积月累,你的 ima 知识库里就有了原始素材。 -![workbuddy添加ima连接器](assets\小程序一键存入ima.jpg) +![将微信收藏保存到 ima](./assets/小程序一键存入ima.jpg) ### 第二步:在 WorkBuddy 中添加 ima 连接器 在 WorkBuddy 中打开连接器管理面板,搜索并添加「ima 知识库」连接器,完成授权。授权完成后,WorkBuddy 就能读取你的 ima 知识库内容了。 -![workbuddy添加ima连接器](assets\workbuddy添加ima连接器.png) +![在 WorkBuddy 中添加 ima 知识库连接器](./assets/workbuddy添加ima连接器.png) ### 第三步:用 WorkBuddy 梳理知识体系