-
Notifications
You must be signed in to change notification settings - Fork 44
docs: drop legacy-html from handbook URLs #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||||||||||
| #!/usr/bin/env python3 | ||||||||||||||||||||||||||||||||||
| """Prepare doc-site/docs from repository Markdown; embed legacy HTML as MkDocs pages.""" | ||||||||||||||||||||||||||||||||||
| """Prepare doc-site/docs from repository Markdown; embed upstream doc/*.html as MkDocs pages under user-guide/chapters/.""" | ||||||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||
|
|
@@ -9,7 +9,10 @@ | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| REPO_ROOT = Path(__file__).resolve().parent.parent | ||||||||||||||||||||||||||||||||||
| OUT_DIR = Path(__file__).resolve().parent / "docs" | ||||||||||||||||||||||||||||||||||
| LEGACY_SUBDIR = "legacy-html" | ||||||||||||||||||||||||||||||||||
| # Handbook-native pages live in user-guide/; imported doc/*.html render under user-guide/chapters/. | ||||||||||||||||||||||||||||||||||
| USER_GUIDE_DIR = "user-guide" | ||||||||||||||||||||||||||||||||||
| IMPORTED_CHAPTERS_DIR = "chapters" | ||||||||||||||||||||||||||||||||||
| OVERVIEW_MD = "overview.md" | ||||||||||||||||||||||||||||||||||
| REPO_URL = os.environ.get("GHP_REPO_URL", "https://github.com/rsyslog/loganalyzer").rstrip("/") | ||||||||||||||||||||||||||||||||||
| DEFAULT_BRANCH = os.environ.get("GHP_DEFAULT_BRANCH", "master").strip() or "master" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -122,13 +125,15 @@ def _ordered_legacy_stems(stems: set[str]) -> list[str]: | |||||||||||||||||||||||||||||||||
| def _format_legacy_nav_lines(stems_ordered: list[str]) -> list[str]: | ||||||||||||||||||||||||||||||||||
| lines = [ | ||||||||||||||||||||||||||||||||||
| LEGACY_NAV_HEADER, | ||||||||||||||||||||||||||||||||||
| " - Overview: legacy-html-manuals.md", | ||||||||||||||||||||||||||||||||||
| " - Quick start: user-guide/quick-start.md", | ||||||||||||||||||||||||||||||||||
| " - Interface map: user-guide/interface-map.md", | ||||||||||||||||||||||||||||||||||
| f" - Overview: {USER_GUIDE_DIR}/{OVERVIEW_MD}", | ||||||||||||||||||||||||||||||||||
| f" - Quick start: {USER_GUIDE_DIR}/quick-start.md", | ||||||||||||||||||||||||||||||||||
| f" - Interface map: {USER_GUIDE_DIR}/interface-map.md", | ||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||
| for stem in stems_ordered: | ||||||||||||||||||||||||||||||||||
| label = LEGACY_NAV_LABELS.get(stem, stem.replace("_", " ").title()) | ||||||||||||||||||||||||||||||||||
| lines.append(f" - {label}: legacy-html/{stem}.md") | ||||||||||||||||||||||||||||||||||
| lines.append( | ||||||||||||||||||||||||||||||||||
| f" - {label}: {USER_GUIDE_DIR}/{IMPORTED_CHAPTERS_DIR}/{stem}.md" | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
132
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The navigation labels should be quoted to ensure the generated
Suggested change
|
||||||||||||||||||||||||||||||||||
| return lines | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -177,6 +182,16 @@ def _write_legacy_markdown( | |||||||||||||||||||||||||||||||||
| out_path.write_text(md, encoding="utf-8", newline="\n") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def _remove_pre_migration_doc_artifacts(out_dir: Path) -> None: | ||||||||||||||||||||||||||||||||||
| """Remove handbook output from the pre-PR layout (legacy-html/, legacy-html-manuals.md).""" | ||||||||||||||||||||||||||||||||||
| legacy_old = out_dir / "legacy-html" | ||||||||||||||||||||||||||||||||||
| if legacy_old.is_dir(): | ||||||||||||||||||||||||||||||||||
| shutil.rmtree(legacy_old) | ||||||||||||||||||||||||||||||||||
| old_hub = out_dir / "legacy-html-manuals.md" | ||||||||||||||||||||||||||||||||||
| if old_hub.is_file(): | ||||||||||||||||||||||||||||||||||
| old_hub.unlink() | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cleanup logic can be made more robust by iterating over the target names and checking for both files and directories. This ensures that if an artifact's type changed (e.g., from a directory to a file) it is still correctly removed.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def main() -> int: | ||||||||||||||||||||||||||||||||||
| OUT_DIR.mkdir(parents=True, exist_ok=True) | ||||||||||||||||||||||||||||||||||
| agents = REPO_ROOT / "AGENTS.md" | ||||||||||||||||||||||||||||||||||
|
|
@@ -188,12 +203,16 @@ def main() -> int: | |||||||||||||||||||||||||||||||||
| text = readme.read_text(encoding="utf-8", errors="replace") | ||||||||||||||||||||||||||||||||||
| (OUT_DIR / "project-readme.md").write_text(text, encoding="utf-8", newline="\n") | ||||||||||||||||||||||||||||||||||
| print(f"Wrote {OUT_DIR / 'project-readme.md'}") | ||||||||||||||||||||||||||||||||||
| _remove_pre_migration_doc_artifacts(OUT_DIR) | ||||||||||||||||||||||||||||||||||
| manuals = REPO_ROOT / "doc" | ||||||||||||||||||||||||||||||||||
| if manuals.is_dir(): | ||||||||||||||||||||||||||||||||||
| legacy_out = OUT_DIR / LEGACY_SUBDIR | ||||||||||||||||||||||||||||||||||
| if legacy_out.is_dir(): | ||||||||||||||||||||||||||||||||||
| shutil.rmtree(legacy_out) | ||||||||||||||||||||||||||||||||||
| legacy_out.mkdir(parents=True, exist_ok=True) | ||||||||||||||||||||||||||||||||||
| guide_root = OUT_DIR / USER_GUIDE_DIR | ||||||||||||||||||||||||||||||||||
| guide_root.mkdir(parents=True, exist_ok=True) | ||||||||||||||||||||||||||||||||||
| chapters_out = guide_root / IMPORTED_CHAPTERS_DIR | ||||||||||||||||||||||||||||||||||
| if chapters_out.is_dir(): | ||||||||||||||||||||||||||||||||||
| shutil.rmtree(chapters_out) | ||||||||||||||||||||||||||||||||||
| chapters_out.mkdir(parents=True, exist_ok=True) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| html_files = sorted(manuals.glob("*.html")) | ||||||||||||||||||||||||||||||||||
| stems = {f.stem for f in html_files} | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -202,11 +221,11 @@ def main() -> int: | |||||||||||||||||||||||||||||||||
| doc_title, body = _extract_title_and_body(raw) | ||||||||||||||||||||||||||||||||||
| body = _rewrite_hrefs(body, stems) | ||||||||||||||||||||||||||||||||||
| md_name = src.with_suffix(".md").name | ||||||||||||||||||||||||||||||||||
| _write_legacy_markdown(legacy_out / md_name, doc_title, body) | ||||||||||||||||||||||||||||||||||
| print(f"Wrote {legacy_out / md_name} <- {src.name}") | ||||||||||||||||||||||||||||||||||
| _write_legacy_markdown(chapters_out / md_name, doc_title, body) | ||||||||||||||||||||||||||||||||||
| print(f"Wrote {chapters_out / md_name} <- {src.name}") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| blob_base = f"{REPO_URL}/blob/{DEFAULT_BRANCH}/doc" | ||||||||||||||||||||||||||||||||||
| rel_prefix = f"{LEGACY_SUBDIR}/" | ||||||||||||||||||||||||||||||||||
| rel_prefix = f"{IMPORTED_CHAPTERS_DIR}/" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ordered = _ordered_legacy_stems(stems) | ||||||||||||||||||||||||||||||||||
| stem_to_html = {f.stem: f.name for f in html_files} | ||||||||||||||||||||||||||||||||||
|
|
@@ -240,12 +259,9 @@ def main() -> int: | |||||||||||||||||||||||||||||||||
| "", | ||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| (OUT_DIR / "legacy-html-manuals.md").write_text( | ||||||||||||||||||||||||||||||||||
| "\n".join(lines) + "\n", | ||||||||||||||||||||||||||||||||||
| encoding="utf-8", | ||||||||||||||||||||||||||||||||||
| newline="\n", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| print(f"Wrote {OUT_DIR / 'legacy-html-manuals.md'}") | ||||||||||||||||||||||||||||||||||
| overview_path = OUT_DIR / USER_GUIDE_DIR / OVERVIEW_MD | ||||||||||||||||||||||||||||||||||
| overview_path.write_text("\n".join(lines) + "\n", encoding="utf-8", newline="\n") | ||||||||||||||||||||||||||||||||||
| print(f"Wrote {overview_path}") | ||||||||||||||||||||||||||||||||||
| _patch_mkdocs_legacy_nav(_ordered_legacy_stems(stems)) | ||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.