markup icon indicating copy to clipboard operation
markup copied to clipboard

Impossible to create a relative link to root of project.

Open cstockton opened this issue 4 years ago • 24 comments

I can't find a way to link to the root of a repository. I am able to make links directly to the root README.md, but what I want is the default view when you visit the repository root, for example: https://github.com/github/markup is not the same as https://github.com/github/markup/blob/master/README.md

After inspecting the code generated by the markdown, I actually think this could be an issue with github routing. I think there is no reason for this to render a 404: https://github.com/github/markup/blob/master/

But this view to work: https://github.com/github/markup/

And these subfolder views to work: https://github.com/github/markup/tree/master/script https://github.com/github/markup/tree/master/lib

It's inconsistent and makes it impossible to create a portable README.md that links to the root of a repo.

======

How to reproduce:

Given the following tree structure:

├── dist
│   └── README.md
├── docs
│   └── README.md
└── README.md

With the following README.md files:

README.md:

# Test

  *[Main](/)* | [Docs] | [Dist]


- FAIL [Main](./) `./  ==>  /<user>/<repo>/blob/main (404)`
- FAIL [Main](/) `/  ==>  /<user>/<repo>/blob/main (404)`
- FAIL [Main](/README.md) `../  ==>  /<user>/<repo>/README.md (want /<user>/<repo>/)`


[Docs]: /docs
[Dist]: ./dist

dist/README.md:

# Test - Dist

  [Main](..) | [Docs] | *[Dist]*


- FAIL [Main](..) `..  ==>  /<user>/<repo>/blob/main (404)`
- FAIL [Main](/) `/  ==>  /<user>/<repo>/blob/main (404)`
- FAIL [Main](../) `../  ==>  /<user>/<repo>/blob/main (404)`
- FAIL [Main](/README.md) `../  ==>  /<user>/<repo>/README.md (want /<user>/<repo>/)`
- FAIL [Main](../README.md) `../  ==>  /<user>/<repo>/README.md (want /<user>/<repo>/)`


[Docs]: ../docs
[Dist]: ../dist

docs/README.md

# Test - Docs

  [Main](/README.md) | *[Docs]* | [Dist]


[Docs]: ../docs
[Dist]: ../dist

cstockton avatar Sep 15 '21 16:09 cstockton

Hello, For me, following works for me:

/../../

See Stackoverflow Question "Relative Link to Repo's Root from Markdown file"

samvilleneuve avatar Feb 01 '22 14:02 samvilleneuve

While that is a workaround it means any time you move the location of the documentation file those links might need to change. While that might work in some cases, other times developers really do want the semantic from the root of the repo in their docs.

Perhaps something like if the first part of the link is a double slash // it should be from inferred as relative to the repo root, or maybe there's another convention available for this.

JDeuce avatar Feb 11 '22 19:02 JDeuce

Really, all that seems to be necessary to solve this issue -- and prevent a 404 when referring to a branch's root using a relative path in a Markdown file -- would be to let the URL

https://github.com/<user>/<repo>/blob/<branch>

redirect to (or be replaced by)

https://github.com/<user>/<repo>/tree/<branch>

just like

https://github.com/<user>/<repo>/blob/<branch>/<folder>

is redirected to

https://github.com/<user>/<repo>/tree/<branch>/<folder>

I'm wondering whether the GitHub Markup project is the place to propose such a solution, though ...

mauritssilvis avatar Mar 18 '22 15:03 mauritssilvis