autosummary mdbook extention
keep SUMMARY.md up to date automatically (drop-in configs) mdBook: SUMMARY.md
TL;DR
Use the mdbook-autosummary preprocessor. It rebuilds SUMMARY.md from your folder tree on every mdbook build/serve. Make it the first preprocessor, set create-missing=false, and start with an empty md/SUMMARY.md that you optionally .gitignore. mdbook-autosummary README mdBook: Preprocessors mdBook: SUMMARY.md
Why not rely on mdbook-toc?
mdbook-toc inserts per-page tables of contents; it does not manage the book-level SUMMARY.md navigation. You still need a valid SUMMARY.md or something to generate it. mdBook: SUMMARY.md
Option A — mdbook-autosummary (recommended) mdbook-autosummary README
- Install:
cargo install mdbook-autosummary - Create an empty file at
md/SUMMARY.md(since yoursrc = "md"). - Update
book.tomlso autosummary runs first and others run after it:
[build] create-missing = false # let autosummary control SUMMARY.md generation
[preprocessor.autosummary]
Your existing preprocessors should declare they run after autosummary:
Section titled “Your existing preprocessors should declare they run after autosummary:”[preprocessor.callouts] command = “mdbook-callouts” after = [“autosummary”]
[preprocessor.mermaid] command = “mdbook-mermaid” after = [“autosummary”]
[preprocessor.toc] command = “mdbook-toc” marker = "" after = [“autosummary”]
Notes:
- Autosummary expects each directory you want in the nav to contain an
index.md, and it prefers the top-level# Headingin each file as the title. mdbook-autosummary README - Because mdBook parses
SUMMARY.mdbefore preprocessors, autosummary uses a reload trick; keepSUMMARY.mdpresent (possibly empty) and consider adding it to.gitignore. mdBook: SUMMARY.md mdbook-autosummary README
Option B — mdbook-auto-gen-summary (preprocessor or CLI) mdbook-auto-gen-summary README
Prefer a simpler tool? This one can run as a preprocessor or be called once as a CLI step in CI to rewrite SUMMARY.md.
As a preprocessor: [build] create-missing = false
[preprocessor.auto-gen-summary] first-line-as-link-text = true # use the first line of each page as nav text
CLI in CI: mdbook-auto-gen-summary gen md # writes md/SUMMARY.md mdbook build
Other options (less common, YMMV)
mdbook-fs-summary: generate the summary from the filesystem instead of keeping an explicit file. mdbook-fs-summarymdbook-summary-generate: another preprocessor that buildsSUMMARY.mdfrom directories/filenames with ordering rules. mdbook-summary-generate
CI tip (keep humans out of SUMMARY.md conflicts)
Add md/SUMMARY.md to .gitignore, and in your pipeline run the generator before mdbook build. That avoids churn in PRs while guaranteeing navigation matches your tree. mdbook-autosummary README mdBook: Preprocessors