10

Using a relative link as directed (https://help.github.com/articles/about-readmes/#relative-links-and-image-paths-in-readme-files) in a PULL_REQUEST_TEMPLATE.md does not relatively link correctly.

When viewed in an actual PR:

  • [CONTRIBUTING.md](/.github/CONTRIBUTING.md)

routes to: https://github.com/.github/CONTRIBUTING.md.

  • [CONTRIBUTING.md](.github/CONTRIBUTING.md)
  • [CONTRIBUTING.md](./.github/CONTRIBUTING.md)

route to: https://github.com/owner/repo/compare/.github/CONTRIBUTING.md

instead of https://github.com/owner/repo/.github/CONTRIBUTING.md.

Changing to ../ to go up a level would work for PRs, but would break the link when viewed in the GitHub UI.

Clicking the link as viewed on GitHub works: https://github.com/fs-webdev/fs-dialog/blob/master/.github/PULL_REQUEST_TEMPLATE.md, just not inside a PR.

(I feel like this used to work in 2017)

What is the correct way to have the relative link function as expected in both cases?

Clif
  • 101
  • 7
  • Relative links never start with a `/`. Try removing the `/` at the start of the link. In fact the linked documentation suggests `./` (the dot is before the slash not after) while you have `/.` – Waylan Mar 12 '18 at 19:04
  • Removing the leading slash or adding a dot before it results in a GitHub comparison link: `https://github.com/owner/repo/compare/.github/CONTRIBUTING.md`, since that is the route a PR originates from. – Clif Mar 12 '18 at 19:10
  • I suspect you either need to do `github/CONTRIBUTING.md` or `./github/CONTRIBUTING.md`. – Waylan Mar 12 '18 at 19:20

1 Answers1

2

Background

Unfortunately, the given implementation seems to consider only the current URL instead of the actual file path in the repository.

The same limitation can be noted when creating issues (through e.g.: https://github.com/owner/repo/issues/new):

[CONTRIBUTING.md](.github/CONTRIBUTING.md)

->

https://github.com/owner/repo/issues/.github/CONTRIBUTING.md

Workaround

I only managed to make the relative link work by specifying the full URL path (including the leading /):

[CONTRIBUTING.md](/owner/repo/.github/CONTRIBUTING.md)

->

https://github.com/owner/repo/.github/CONTRIBUTING.md

With that said, the abstraction can only go up to the URL host (i.e.: https://github.com).

kelvin
  • 1,421
  • 13
  • 28