Skip to content

README images with root-relative paths do not load #2961

Description

@jasongitmail

Expected behavior

Root-relative README image paths should load on npmx.dev when the package metadata identifies a GitHub repository.

Actual behavior

Root-relative README images do not load on npmx.dev.

For example, this README image:

<img src="/docs/assets/readme-header.webp" alt="Package header">

is rendered as-is, so the browser requests:

https://npmx.dev/docs/assets/readme-header.webp

That 404s because the path is resolved against npmx.dev, not the package repository.

Behavior on npmjs.com and GitHub

The same README image loads correctly on both npmjs.com and GitHub.

GitHub resolves the root-relative path against the repository.

npmjs.com rewrites the image to a raw GitHub asset URL, roughly like:

https://raw.githubusercontent.com/<owner>/<repo>/HEAD/docs/assets/readme-header.webp

Proposed solution

When rendering README images with a root-relative src, rewrite:

/docs/assets/readme-header.webp

to:

https://raw.githubusercontent.com/<owner>/<repo>/HEAD/docs/assets/readme-header.webp

using the package repository owner and repo from package metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending triageNew issue waiting for initial maintainer triage

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions