From 0d3df1cdf308956729f24d4f5c1462ec44b3184c Mon Sep 17 00:00:00 2001 From: Yuval Kogman Date: Wed, 21 Oct 2026 21:42:46 +0200 Subject: [PATCH] Rewrite README chapter links when assembling the mdbook The repo root README uses docs/ paths for GitHub, buta mdbook assembly places it alongside the chapters. This change ensures that the README can link to chapters in both contexts. --- contrib/book.py | 2 +- contrib/test_book.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/book.py b/contrib/book.py index 3c199b8..1cf9b79 100644 --- a/contrib/book.py +++ b/contrib/book.py @@ -117,7 +117,7 @@ def assemble(root): if clash := sorted(name for name in pages if name.casefold() in reserved): raise ValueError(f"generated by book.py: {', '.join(clash)}") generated = { - "README.md": (root / "README.md").read_text(), + "README.md": re.sub(r"(?<=\]\()docs/", "", (root / "README.md").read_text()), "SUMMARY.md": summary(index, pages), CONTENTS: contents(index), } diff --git a/contrib/test_book.py b/contrib/test_book.py index 0454251..25f5c09 100644 --- a/contrib/test_book.py +++ b/contrib/test_book.py @@ -167,7 +167,7 @@ def test_assembly_covers_every_chapter(tmp_path): "one.md", "sub/two.md", ] - assert (out / "README.md").read_text() == "# Intro\n\nSee [one](docs/one.md).\n" + assert (out / "README.md").read_text() == "# Intro\n\nSee [one](one.md).\n" contents = (out / "contents.md").read_text() assert "* [Two](sub/two.md) - The second chapter." in contents assert (out / "one.md").read_text() == "# One\n"