DEV Community

Cover image for Prepare your Rust API docs for Github Pages

Prepare your Rust API docs for Github Pages

Ben Lovy on November 09, 2021

Rust comes with a built-in documentation system, rustdoc. It's great, use it. Github comes with a built-in web hosting service, Github Pages. It...
Collapse
 
zperk13 profile image
Zoe • Edited

I translated the script (and reordered it slightly) for a Windows bat file. Use as you please

cargo doc --no-deps
rmdir /s ./docs
robocopy target/doc docs /s
echo|set /p="<meta http-equiv="refresh" content="0; url=PROJECT_NAME/index.html">" > docs/index.html
Enter fullscreen mode Exit fullscreen mode
Collapse
 
timclicks profile image
Tim McNamara

This is quite cunning. I like it.

Collapse
 
ssokolow profile image
Stephan Sokolow

It's also how I ensured no broken links when I was migrating the root ssokolow.com site to Jekyll.

Just have a bunch of folders containing redirecting index.html files named after the old non-HTML routes from when I was using MoinMoin. (eg. ssokolow.com/ContactMe )

Collapse
 
dystroy profile image
Denys Séguret

This is interesting but why not using docs.rs where all documentations are available as soon as you publish your crate ?

Collapse
 
deciduously profile image
Ben Lovy • Edited

I'm using this for a crate that's part of a build process specific to one project. It's not likely to end up published, but I still want to provide accessible documentation. You're definitely right for most public packages, just use the existing infrastructure!