Skip to content

Relative URL replacement breaks links to directories #94

@BobbieGoede

Description

@BobbieGoede

Environment

n/a

Reproduction

See https://unjs.io/packages/magicast, specifically the links to the source code and test cases near the bottom highlighted here. Navigating to these links (https://raw.githubusercontent.com/unjs/magicast/main/src/helpers or https://raw.githubusercontent.com/unjs/magicast/main/test/helpers) will result in a 404 page.

Describe the bug

The original issue was that relative links did not work outside Github, see #24 which was resolved by #52.

The solution was to replace the relative URLs with absolute ones, essentially prefixing with 'https://raw.githubusercontent.com', this works fine for images/assets but does not work for directories. As seen on magicast docs, ./src/helpers is replaced with https://raw.githubusercontent.com/unjs/magicast/main/src/helpers.

Not sure how this can be resolved 🤔 I'm assuming checking each URL for a 404 would be a bit too much. Maybe checking for file extensions? But some file links have no extension like LICENSE.

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions