Skip to content

Relative linking should not be broken when you're linking from an index page. #259

Open
@jhchabran

Description

@jhchabran

In the content, we are using only absolute links, which is the consequence of a bug with how we handle URLs.

While we can work with it for the time being, it's not good at all for maintenance, and it's very incovenient when writing docs to always have to write absolute links. Relative links are a very basic concept that everyone expects to exist, and it makes it much simpler to move pages around.

  • If a page is living under docs/a/b/index.mdx the page will be served as https//sourcegraph.com/docs/a/b (note the absence of a final slash).
  • If a page is living under docs/a/b/page.mdx the page will be served as https://sourcegraph.com/docs/a/b/page

Both are correct, but the problem lies in how we're rendering the links. Assuming we have the following structure:

docs/a/b/index.mdx
docs/a/b/page1.mdx 
docs/a/b/page2.mdx
docs/a/b/c/index.mdx
docs/a/b/c/page.mdx
  • OK: If within docs/a/b/page1.mdx you write [some link to page2](page2) it will be rendered as https://sourcegraph.com/docs/a/b/page2
  • BUG: If within docs/a/b/index.mdx you write [some link to page2](page2) it will be rendered as https://sourcegraph.com/docs/a/page2
  • OK: If within docs/a/b/page1.md you write [some link to c/page2](c/page2) it will be rendered as https://sourcegraph/com/a/b/c/page2
  • BUG: If within docs/a/b/index.md you write [some link to c/page2](c/page2) it will be rendered as https://sourcegraph/com/a/c/page2

This is happenening because we're removing the trailing slash for cosmetic purposes but we aren't reflecting this behaviour when rendering links, it instead does the classic thing, which is to simply go back to the parent folder. If we had the trailing slash, .i.e https://sourcegraph.com/docs/a/b/ it would have worked.

I understand the reasoning with not having the trailing slash (and it makes sense) and I'm not advocating for changing that. But instead we should ensure that the link rendering code correctly handles this.

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