rust-lang / mdBook

Create book from markdown files. Like Gitbook but implemented in Rust
https://rust-lang.github.io/mdBook/
Mozilla Public License 2.0
18.47k stars 1.65k forks source link

Broken relative links when using first chapter as an index page. #2060

Open HU90m opened 1 year ago

HU90m commented 1 year ago

Problem

If there is no index page in the source directory, mdBook uses the first chapter as the index page. When doing so, mdBook doesn't render the page any differently. This causes relative links on the page to break, if the first chapter is within a sub-directory.

Steps

I've created a repo for easy recreation: https://github.com/HU90m/mdbook-broken-landing-page-links.

Possible Solution(s)

I think the most elegant solution is to use a redirect to the first chapter, if no index page is given. I've put together a fix, before reading the issue assignment section of the contributor's guide 🙃.

You can find my suggested fix at https://github.com/HU90m/mdBook/tree/landing-page-links-fix . I'll happily open a PR if this solution sounds good to you. (I thought I'd avoid bombarding you with both an issue and PR.

Notes

No response

Version

`v0.4.28`
Leroy-X commented 1 year ago

Hi, may I ask when it will be fixed? It is now version 0.4.35. The problem still exists. I look forward to fixing it soon. Thanks.

HU90m commented 1 year ago

https://github.com/rust-lang/mdBook/pull/2077 should fix it. It's currently awaiting reviews.

Do see if this patch fixes the problem for you and do review the PR if you know (or are learning) Rust.

Leroy-X commented 1 year ago

@HU90m Thank you very much for your reply, I'm not a developer and don't use Rust.

J3rome commented 6 months ago

I am also facing this issue (#2380). I haven't looked deeply at the code (I'm a rust noob) but I've observed that the links in the print.html page get properly rewritten. Perhaps the logic used when generating the print.html could be reused instead of doing a redirect ?