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; }