Closed
Description
A linkchecker is a convenient tool to have for avoiding errors and keeping track of dead links. It is also a nice to have for #308.
The RBE linkchecker and the one used in rust-lang/rust both scan the files line-by-line while applying a regex to find links and check them. I don't know if it'd be OK for us to adopt the rust-lang/rust one? @steveklabnik
I think a good place for this would be mdbook test
.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Michael-F-Bryan commentedon Jun 24, 2017
This would be a good candidate for the plugin system (#163). Ideally, after the rendering stage you'd be able to make a plugin which gets passed the rendered output's location and then checks all the links in all the
*.html
files it can find.We're planning on refactoring the current system to make it a lot easier to write your own plugins and renderers.
azerupi commentedon Jun 24, 2017
Definitely in
mdbook test
I agree, this could potentially be written as a plugin in the future :)
I emphasised "in the future" because I don't want to stall progress on changes that are coming soon-ish. We don't have a deadline for the plugin system, so if someone wants to contribute a solution right now, I wouldn't want to break their inertia.
However, we can keep this use case in the back of our minds when doing the refactorings, to make it indeed possible to implement this as a plugin later. :)
steveklabnik commentedon Jun 24, 2017
budziq commentedon Jun 24, 2017
It might be nice to have it as a warning also on
mdbook build
stage@steveklabnik That would be awesome!
Michael-F-Bryan commentedon Jan 13, 2018
For anyone interested, I've started playing around with a mdbook-linkcheck backend for checking links. You'll need to install
mdbook
directly frommaster
and isn't 100% finished yet, but it may be useful for some people.EDIT: It looks like the tool works, because I've already found my first batch of broken links, rust-lang/rust-by-example#990 🎉
Example Output
This is the output (when logging very verbosely) when the tool is run over mdbook's user: guide
projektir commentedon Jan 13, 2018
@Michael-F-Bryan so rust-lang/rust already has a linkchecker, which is the one we originally wanted to pull out and turn into a crate (I'm not sure what that means for plugins). It has some problems, though, that yours doesn't have (for instance, this fix is really needed), but it also does some things yours doesn't (check for absolute paths).
Idk if we want to have these out of sync given that rust-lang/rust's linkchecker would run on every
x.py
build for all the books that it manages.Michael-F-Bryan commentedon Jan 13, 2018
My original hopes were that this could supplement (or even succeed?) their link checker, although on further inspection they do a lot of cross-site linking (i.e. using links to files outside the book such as
../../std/prelude/index.html
). My linkchecker works purely with the source book and doesn't take into account the fact that other things exist on the Rust S3 bucket, so I don't know whether this is still possible.That said, the entire idea behind enabling alternate backends is that people can write their own tools to suit their exact use case. For example, it was almost trivial to knock up a backend which runs everything through
rust-skeptic
, which is something Rust By Example currently need to do manually.This part was tricky. I originally treated relative and absolute paths separately (relative links are relative to the chapter's directory, absolute is relative to
src/
) but found that most of the links in Rust By Example used a completely different convention. We use the<base>
tag to tweak how links get resolved by your browser, so what I detected as a "broken link" turned out to still work fine when viewing online.9 remaining items