A backend for mdbook
which will check your links for you. For use alongside
the built-in HTML renderer.
First you'll need to install mdbook-linkcheck
.
cargo install mdbook-linkcheck
If you don't want to install from source (which often takes a while) you can
grab an executable from GitHub Releases or use this line of
curl
:
console
curl -LSfs https://japaric.github.io/trust/install.sh | \
sh -s -- --git Michael-F-Bryan/mdbook-linkcheck
Next you'll need to update your book.toml
to let mdbook
know it needs to
use mdbook-linkcheck
as a backend.
```toml [book] title = "My Awesome Book" authors = ["Michael-F-Bryan"]
[output.html]
[output.linkcheck] ```
And finally you should be able to run mdbook build
like normal and everything
should Just Work.
$ mdbook build
Note: When multiple
[output]
items are specified,mdbook
tries to ensure that each[output]
gets its own sub-directory within thebuild-dir
(book/
by default).That means if you go from only having the HTML renderer enabled to enabling both HTML and the linkchecker, your HTML will be placed in
book/html/
instead of justbook/
like before.
The link checker's behaviour can be configured by setting options under the
output.linkcheck
table in your book.toml
.
```toml ...
[output.linkcheck]
follow-web-links = false
traverse-parent-directories = false
./index.html
in [some page](./index.html)
) so it can be used to#
exclude = [ 'google.com' ]
user-agent = "mdbook-linkcheck-0.4.0"
cache-timeout = 43200
#
warning-policy = "warn"
#
[output.linkcheck.http-headers]
'crates.io' = ["Accept: text/html"]
#
$
symbol, like \$TOKEN
.\
itself can also be escaped via \\
.#
'website.com' = ["Authorization: Basic $TOKEN"] ```
Incorporating mdbook-linkcheck
into your CI system should be straightforward
if you are already using mdbook
to generate documentation.
For those using GitLab's built-in CI:
```yaml generate-book: stage: build image: name: michaelfbryan/mdbook-docker-image:latest entrypoint: [""] script: - mdbook build $BOOKDIR artifacts: paths: - $BOOKDIR/book/html # make sure GitLab doesn't accidentally keep every book you ever generate # indefinitely expire_in: 1 week
pages: image: busybox:latest stage: deploy dependencies: - generate-book script: - cp -r $BOOK_DIR/book/html public artifacts: paths: - public only: - master ```
The michaelfbryan/mdbook-docker-image docker image is also available
on Docker hub and comes with the latest version of mdbook
and
mdbook-linkcheck
pre-installed.