mdBook Utilities
This is a Work In Progress.
mdbook-utils manages links, reference definitions, and code examples in Markdown files, especially mdbook source directories.
It is the companion tool for the "Rust How-to" book (github).
Usage
Run the tool without arguments to display the the list of commands:
refdefs Manage reference definitions
links Manage links
markdown Manage code blocks (embedded examples) and includes
sitemap Generate a sitemap.xml file from the list of Markdown files in a source directory
debug Parse the entire Markdown code as events and write them to a file
help Print this message or the help of the given subcommand(s)
In turn, each command offers a menu of subcommands. Try e.g. mdbook-utils refdefs.
Use mdbook-utils <command> <subcommand> --help or help <command> <subcommand> for more details.
Command-line options and environment variables
Each subcommand uses defaults that are overwritten by values in book.toml (if present), by environment variables (if set), or command-line options (the latter trumps the former).
Command-line options vary by subcommand and include -o to set the path of the output file; -m to set the path of the source Markdown directory (./src or ./drafts by default, depending on the subcommand); -c to set the path to the directory containing the Cargo.toml that declares the dependencies (Rust crates) used in the book; and -t to set the path to the destination directory.
You may export environment variables manually or store them in a .env file:
# Root directory of the book
# `book.toml` is looked up in BOOK_ROOT_DIR_PATH, if set,
# otherwise the current working directory.
# Markdown source directory
# Directory where mdbook outputs the book's HTML and JS;
# typically ./book/ or ./book/html/
# Directory where `Cargo.toml` may be found
# Default destination directory for mdbook-utils outputs.
# Base url of the website where the book will be deployed
# (used to build sitemaps)
You may also set the RUST_LOG environment variable to display the logs.
See cli/config.rs for more details.
Development
The following is of interest only if you want to contribute to the project.
mdbook-utils is written in Rust.
Repo structure
- The source code is in the
srcfolder. The main executable is inmain.rsand theclimodule. It calls the API inlib.rs. - A simple test
mdbookbook is found intest_book. - The Dev Container and Docker (Compose) configuration files are found in
.devcontainer.devcontainer.jsonuses Docker Compose (configured incompose.yamlandcompose.override.yaml), which in turn creates a container fromDockerfile.
.githubcontains the CI GitHub Actions workflow.
Installation
Using VS Code
Clone the repo and open the folder in VS Code. Edit .devcontainer/.env if needed. VS Code should prompt you to open the code in a docker container, which installs rust tooling automatically. Make sure you have previously installed
- Dev Container extension
- Docker Desktop (or at least the Docker engine).
Note that opening the code folder in VS Code may take a little while the first time around.
Other
If you are not using VS Code, install the Dev Container CLI, use Docker Compose directly (see below), or simply install the required tools on your local machine.
The following works with Ubuntu and Windows WSL:
# Optional
Review .devcontainer/Dockerfile for other optional dependencies.
Build and test the code
The just command runner is configured to simplify compilation and testing.
Type just at a shell prompt for a list of commands:
Docker Compose
Test the Docker Compose setup used during developement (which Dev Containers runs) with:
# or simply
Publish to crates.io
- Go to
crates.io, sign in, and create an API token inAccount Settings>API Tokens. - Use
cargo loginto save the token in$CARGO_HOME/credentials.toml. just build; just clippy; just run; just doc; cargo package- Review the packaging output in
/cargo-target-mdbook-utils/target/package. - When ready,
cargo publish --dry-run; cargo publish
Links
mdbook-utils' GitHub repo