From d8c6a4093d32be8d37917b0e23f19f039f2db4c0 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Thu, 23 Apr 2026 23:14:51 +0800 Subject: [PATCH] fix(export): normalize all site-relative markdown image urls Made-with: Cursor --- app/utils/markdown-export.test.ts | 7 +++++++ app/utils/markdown-export.ts | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/utils/markdown-export.test.ts b/app/utils/markdown-export.test.ts index 60ef3e6..f754c8e 100644 --- a/app/utils/markdown-export.test.ts +++ b/app/utils/markdown-export.test.ts @@ -13,6 +13,13 @@ describe("normalizeMarkdownImageUrls", () => { expect(result).toBe("![cover](https://example.com/public/assets/posts/cover.png)"); }); + test("converts other site-relative image links to absolute URLs", () => { + const markdown = "![hero](/images/a.png)"; + const result = normalizeMarkdownImageUrls(markdown, "https://example.com"); + + expect(result).toBe("![hero](https://example.com/images/a.png)"); + }); + test("keeps absolute http/https image links unchanged", () => { const markdown = [ "![a](http://cdn.example.com/a.png)", diff --git a/app/utils/markdown-export.ts b/app/utils/markdown-export.ts index 74ac5ad..72be5db 100644 --- a/app/utils/markdown-export.ts +++ b/app/utils/markdown-export.ts @@ -3,8 +3,6 @@ type MarkdownExportFileNameInput = { id: number; }; -const PUBLIC_ASSETS_PREFIX = "/public/assets/"; - function isAbsoluteOrSpecialUrl(url: string): boolean { return /^(https?:)?\/\//i.test(url) || /^data:/i.test(url); } @@ -17,7 +15,7 @@ export function normalizeMarkdownImageUrls(markdown: string, origin: string): st return full; } - if (!rawUrl.startsWith(PUBLIC_ASSETS_PREFIX)) { + if (!rawUrl.startsWith("/")) { return full; }