Skip to content

Commit 6ff08c5

Browse files
enforce nav order for implementation domains and system levels
1 parent ae6ea4e commit 6ff08c5

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

_data/sources.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"ref": "main",
88
"subdir": "docs",
99
"mount": "implementation-domains/breads",
10+
"nav_order": 1,
1011
"redirect_from": [
1112
"/breads/",
1213
"/breads"
@@ -23,6 +24,7 @@
2324
"ref": "main",
2425
"subdir": "docs",
2526
"mount": "implementation-domains/froots",
27+
"nav_order": 2,
2628
"redirect_from": [
2729
"/froots/",
2830
"/froots"
@@ -39,6 +41,7 @@
3941
"ref": "main",
4042
"subdir": "docs",
4143
"mount": "implementation-domains/protins",
44+
"nav_order": 3,
4245
"redirect_from": [
4346
"/protins/",
4447
"/protins"
@@ -55,6 +58,7 @@
5558
"ref": "main",
5659
"subdir": "docs",
5760
"mount": "implementation-domains/sugirs",
61+
"nav_order": 4,
5862
"redirect_from": [
5963
"/sugirs/",
6064
"/sugirs"
@@ -71,6 +75,7 @@
7175
"ref": "main",
7276
"subdir": "docs",
7377
"mount": "system-levels/slice",
78+
"nav_order": 1,
7479
"redirect_from": [
7580
"/slice/",
7681
"/slice"
@@ -87,6 +92,7 @@
8792
"ref": "main",
8893
"subdir": "docs",
8994
"mount": "system-levels/loaf",
95+
"nav_order": 2,
9096
"redirect_from": [
9197
"/loaf/",
9298
"/loaf"
@@ -103,6 +109,7 @@
103109
"ref": "main",
104110
"subdir": "docs",
105111
"mount": "system-levels/batch",
112+
"nav_order": 3,
106113
"redirect_from": [
107114
"/batch/",
108115
"/batch"
@@ -119,6 +126,7 @@
119126
"ref": "main",
120127
"subdir": "docs",
121128
"mount": "system-levels/oven",
129+
"nav_order": 4,
122130
"redirect_from": [
123131
"/oven/",
124132
"/oven"

scripts/ensure_front_matter.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
argv[1] : Path to the imported project root (mount directory)
2626
Env.PROJECT_TITLE : Optional project display name (defaults to directory name)
2727
Env.REDIRECT_FROM : Optional JSON array or string for redirect_from on hub
28+
Env.NAV_ORDER : Optional integer for nav_order on hub
2829
2930
Outputs
3031
-------
@@ -135,12 +136,15 @@ def _normalize_redirect_from(
135136
return sorted(out)
136137

137138

138-
def ensure_hub_index(root: Path, project_title: str, redirect_from_env: str) -> Path:
139+
def ensure_hub_index(
140+
root: Path, project_title: str, redirect_from_env: str, nav_order_env: str
141+
) -> Path:
139142
"""
140143
Create or normalize the hub page at <root>/index.md.
141144
142145
Forces canonical title and section semantics. Merges redirect_from entries
143146
from REDIRECT_FROM env to support legacy slugs via jekyll-redirect-from.
147+
Sets nav_order if provided in NAV_ORDER env.
144148
"""
145149
hub = root / "index.md"
146150
if hub.exists():
@@ -155,6 +159,13 @@ def ensure_hub_index(root: Path, project_title: str, redirect_from_env: str) ->
155159
fm.pop("parent", None)
156160
fm.pop("grand_parent", None)
157161

162+
# Set nav_order if provided
163+
if nav_order_env and nav_order_env.strip():
164+
try:
165+
fm["nav_order"] = int(nav_order_env.strip())
166+
except ValueError:
167+
pass # Ignore invalid nav_order values
168+
158169
redirects = _normalize_redirect_from(redirect_from_env, fm.get("redirect_from"))
159170
if redirects:
160171
fm["redirect_from"] = redirects
@@ -243,8 +254,9 @@ def main(argv: list[str]) -> int:
243254
root = Path(argv[1]).resolve()
244255
project_title = os.environ.get("PROJECT_TITLE", root.name).strip() or root.name
245256
redirect_from_env = os.environ.get("REDIRECT_FROM", "")
257+
nav_order_env = os.environ.get("NAV_ORDER", "")
246258

247-
hub = ensure_hub_index(root, project_title, redirect_from_env)
259+
hub = ensure_hub_index(root, project_title, redirect_from_env, nav_order_env)
248260

249261
for path in root.rglob("*"):
250262
process_page(root, hub, project_title, path)

scripts/import_sources.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# * Rsync the selected subtree into the local .mount path
1010
# - Respects per-source "exclude" globs and per-repo ".indexignore"
1111
# * Normalize front matter for Just the Docs via ensure_front_matter.py
12-
# - Passes PROJECT_TITLE and REDIRECT_FROM (JSON) env vars
12+
# - Passes PROJECT_TITLE, REDIRECT_FROM (JSON), and NAV_ORDER env vars
1313
#
1414
# Inputs:
1515
# sources.json entries:
@@ -21,6 +21,7 @@
2121
# - mount : destination mount path in this repo
2222
# - exclude[] : optional rsync exclude patterns
2323
# - redirect_from[] : optional legacy slugs (or "redirects[]" for bw-compat)
24+
# - nav_order : optional integer for navigation ordering
2425
#
2526
# Requirements: bash, git, jq, rsync
2627
# Safe defaults: set -euo pipefail, strict quoting, basic path sanitization.
@@ -109,7 +110,8 @@ jq -c '.sources[]' "$MANIFEST" | while IFS= read -r row; do
109110
echo "::group::Normalize front matter for ${mount}"
110111
# Accept either "redirect_from" or legacy "redirects"
111112
redirect_from_json="$(jq -c '.redirect_from? // .redirects? // []' <<<"$row")"
112-
PROJECT_TITLE="$title" REDIRECT_FROM="$redirect_from_json" \
113+
nav_order="$(jq -r '.nav_order? // ""' <<<"$row")"
114+
PROJECT_TITLE="$title" REDIRECT_FROM="$redirect_from_json" NAV_ORDER="$nav_order" \
113115
python3 "${ROOT}/scripts/ensure_front_matter.py" "$MOUNT_ABS"
114116
echo "::endgroup::"
115117
done

0 commit comments

Comments
 (0)