Skip to content

Commit 3c2b459

Browse files
author
Kunal jaiswal
authored
fix(pages): remove incorrect publicPath prefix from absolute image paths (#428) (#438)
MarkdownRenderer.image computed a publicPath from window.location.pathname and prepended it to absolute image hrefs. On pages nested more than one level deep (e.g. /blog/introducing-ocr-blog), this produced broken URLs like /blog/images/blog/... resulting in 404s. Since webpack publicPath is '/' (root deployment), absolute paths are already correct. Remove the publicPath computation and use href directly as src. Closes #428
1 parent be7c591 commit 3c2b459

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

pages/src/components/MarkdownRenderer.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content }) => {
7878
}, [toastVisible]);
7979

8080
const html = useMemo(() => {
81-
const publicPath = (window.location.pathname.replace(/\/[^/]*$/, '') || '').replace(/\/$/, '');
8281
// Custom renderer to generate heading IDs matching the TOC extraction logic
8382
const renderer = new Renderer();
8483
renderer.image = function ({ href, title, text }: { href: string; title?: string | null; text: string }) {
8584
const escapeAttr = (s: string) => s.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
86-
const src = href.startsWith('/') ? `${publicPath}${href}` : href;
8785
const titleAttr = title ? ` title="${escapeAttr(title)}"` : '';
88-
return `<img src="${escapeAttr(src)}" alt="${escapeAttr(text)}"${titleAttr} />`;
86+
return `<img src="${escapeAttr(href)}" alt="${escapeAttr(text)}"${titleAttr} />`;
8987
};
9088
renderer.heading = function ({ text, depth }: { text: string; depth: number }) {
9189
const id = generateHeadingId(text);

0 commit comments

Comments
 (0)