feat: list each declared doc kind as its own homepage card
- compute per-kind home URLs (lib/, api/, wiki/) via _find_home_for_kind - emit one card per declared kind so multi-kind repos (e.g. doc-forge with lib + wiki) appear in each matching homepage section - declare the doc-forge wiki kind and refresh its vendored site with the combined lib + wiki build
This commit is contained in:
41
collect.py
41
collect.py
@@ -61,6 +61,18 @@ def _find_home(dest: Path) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def _find_home_for_kind(dest: Path, kind: str) -> str:
|
||||
"""After copying a site into *dest*, return the relative URL path for a
|
||||
specific doc kind. A root index.html serves every kind; otherwise each
|
||||
kind is found under its own subdirectory (lib/, api/, wiki/)."""
|
||||
if (dest / "index.html").exists():
|
||||
return ""
|
||||
sub = dest / kind
|
||||
if kind in ("lib", "api", "wiki") and (sub / "index.html").exists():
|
||||
return f"{kind}/"
|
||||
return _find_home(dest)
|
||||
|
||||
|
||||
# ── index.html generator ────────────────────────────────────────────────────
|
||||
|
||||
INDEX_TEMPLATE = r"""<!DOCTYPE html>
|
||||
@@ -154,24 +166,33 @@ def _render_section(title: str, cards: list[tuple[str, str, str, str]]) -> str:
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def build_index_html(config: dict, home_urls: dict[str, str]) -> str:
|
||||
def build_index_html(
|
||||
config: dict,
|
||||
home_urls: dict[str, str],
|
||||
kind_urls: dict[tuple[str, str], str] | None = None,
|
||||
) -> str:
|
||||
lib_cards: list[tuple[str, str, str, str]] = []
|
||||
api_cards: list[tuple[str, str, str, str]] = []
|
||||
wiki_cards: list[tuple[str, str, str, str]] = []
|
||||
tutorial_cards: list[tuple[str, str, str, str]] = []
|
||||
|
||||
kind_urls = kind_urls or {}
|
||||
|
||||
for entry in config.get("repos", []):
|
||||
docs = entry.get("docs") or {}
|
||||
name = entry["name"]
|
||||
title = _safe_title(entry)
|
||||
desc = _safe_description(entry)
|
||||
url = home_urls.get(name, f"/{name}/")
|
||||
base_url = home_urls.get(name, f"/{name}/")
|
||||
if docs.get("lib"):
|
||||
url = kind_urls.get((name, "lib"), base_url)
|
||||
lib_cards.append((title, desc, url, "View Documentation"))
|
||||
elif docs.get("api"):
|
||||
api_cards.append((title, desc, url, "View Documentation"))
|
||||
elif docs.get("wiki"):
|
||||
if docs.get("wiki"):
|
||||
url = kind_urls.get((name, "wiki"), base_url)
|
||||
wiki_cards.append((title, desc, url, "View Documentation"))
|
||||
if docs.get("api"):
|
||||
url = kind_urls.get((name, "api"), base_url)
|
||||
api_cards.append((title, desc, url, "View Documentation"))
|
||||
|
||||
for entry in config.get("static", []):
|
||||
kind = entry.get("kind")
|
||||
@@ -273,13 +294,19 @@ def collect(config: dict, dry_run: bool = False) -> list[str]:
|
||||
|
||||
# ── compute home URLs ───────────────────────────────────────────────────
|
||||
if not dry_run:
|
||||
kind_urls: dict[tuple[str, str], str] = {}
|
||||
for entry in config.get("repos", []):
|
||||
home_urls[entry["name"]] = f"/{entry['name']}/{_find_home(ROOT / entry['name'])}"
|
||||
name = entry["name"]
|
||||
dest = ROOT / name
|
||||
home_urls[name] = f"/{name}/{_find_home(dest)}"
|
||||
for kind in ("lib", "api", "wiki"):
|
||||
if (entry.get("docs") or {}).get(kind):
|
||||
kind_urls[(name, kind)] = f"/{name}/{_find_home_for_kind(dest, kind)}"
|
||||
for entry in config.get("static", []):
|
||||
home_urls[entry["repo"]] = f"/{entry['repo']}/{_find_home(ROOT / entry['repo'])}"
|
||||
|
||||
# ── regenerate outputs ──────────────────────────────────────────────
|
||||
index_html = build_index_html(config, home_urls)
|
||||
index_html = build_index_html(config, home_urls, kind_urls)
|
||||
(ROOT / "_index" / "index.html").write_text(index_html, encoding="utf-8")
|
||||
nginx_conf = build_nginx_conf(service["html_port"])
|
||||
(ROOT / "nginx.conf").write_text(nginx_conf, encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user