Skip to content

fix(pages): blog images broken — MarkdownRenderer incorrectly prefixes absolute paths with route segment #428

Description

@lizhengfeng101

Description

Images in blog posts fail to load (404) because MarkdownRenderer computes a publicPath from window.location.pathname and prepends it to absolute image href values.

For a blog post at /blog/introducing-ocr-blog, the logic on line 81 of MarkdownRenderer.tsx:

const publicPath = (window.location.pathname.replace(/\/[^/]*$/, '') || '').replace(/\/$/, '');
// → "/blog"

Then on line 86:

const src = href.startsWith('/') ? `${publicPath}${href}` : href;
// href = "/images/blog/introducing-ocr-blog/demo.png"
// src  = "/blog/images/blog/introducing-ocr-blog/demo.png"  ← 404

The webpack config already sets publicPath: '/' (root deployment), so all absolute image paths (starting with /) should be used as-is without any prefix.

Expected behavior: ![alt](/images/blog/introducing-ocr-blog/demo.png) resolves to /images/blog/introducing-ocr-blog/demo.png.

Actual behavior: It resolves to /blog/images/blog/introducing-ocr-blog/demo.png (404).

Scope

  • File: pages/src/components/MarkdownRenderer.tsx
  • Function: renderer.image inside the html useMemo (lines 80–89)
  • The fix is small: remove the publicPath computation and use href directly as src for absolute paths.

Acceptance Criteria

  • Images in blog posts render correctly (e.g., /blog/introducing-ocr-blog shows demo.png)
  • Images still work on the docs page (/docs/*)
  • Code check passes (make check)

Context

Discovered while viewing the introducing-ocr-blog post — the "Open Code Review 首页" demo image does not render. The publicPath logic was likely intended for sub-path deployments (e.g., GitHub Pages at /open-code-review/) but is incorrect for the current root-path deployment, and breaks on any page deeper than one level.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions