Skip to content

Commit 5235a1c

Browse files
committed
feat: make the navbar self-describing for remote clients
navbar.json identified each chapter by id and display name only, while its documents are generated into a slug directory. As a local bundle a client could carry its own ordered list of directories; as a remote API there was no way to build a URL from the navbar at all, and any change to a chapter's nav_order would silently repoint a hardcoded list at the wrong chapter. Each chapter now carries the directory it was generated into, so a client can request "<base>/<path>/0.json" for a chapter index and "<base>/<path>/<id>.json" for a section. The field is additive; existing consumers ignore it. Verified that every URL derivable from navbar.json resolves to valid JSON, and that no generated document is unreachable from it.
1 parent e391ac8 commit 5235a1c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

utils/md2json/book.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ def discover_chapters(docs: Path) -> list[Chapter]:
6767

6868

6969
def build_navbar(chapters: list[Chapter]) -> dict:
70-
"""Build the navigation document listing chapters and their sections."""
70+
"""Build the navigation document listing chapters and their sections.
71+
72+
Each chapter carries the directory it was generated into, so a client can
73+
build "<base>/<path>/<id>.json" for a section and "<base>/<path>/0.json" for
74+
the chapter index without knowing the chapter ordering in advance.
75+
"""
7176
return {
7277
"chapters": [
7378
{
7479
"id": chapter_id,
7580
"name": chapter.title,
81+
"path": chapter.directory,
7682
"sub-chapters": [
7783
{"id": number, "name": section.title}
7884
for number, section in enumerate(chapter.sections, start=1)

0 commit comments

Comments
 (0)