Skip to content

Commit cafe64f

Browse files
committed
Add way to have cleaner mkdocs separation
1 parent 6d19b76 commit cafe64f

4 files changed

Lines changed: 88 additions & 2 deletions

File tree

docs_dev/readme_toplevel.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hello world

docs_dev/user

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs_dev/utils/mirror_docs.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
"""Mirror docs/ and docs_dev/ into a unified virtual FS for MkDocs.
3+
4+
Virtual output structure:
5+
readme.md ← from docs_dev/readme_toplevel.md
6+
user/ ← from docs/
7+
dev/ ← from docs_dev/ (excluding utils/, requirements.txt, readme_toplevel.md)
8+
"""
9+
10+
from __future__ import annotations
11+
12+
from pathlib import Path
13+
14+
DOCS_DEV_EXCLUDE = {
15+
16+
}
17+
18+
19+
def _repo_root_from_script(script_path: Path) -> Path:
20+
"""Infer repository root from script location."""
21+
return script_path.parents[2]
22+
23+
24+
def _mirror_into_virtual_fs(
25+
source_dir: Path,
26+
virtual_prefix: str,
27+
exclude: set[str] | None = None,
28+
) -> None:
29+
"""Read all files from source_dir and write them into the mkdocs virtual FS.
30+
31+
Args:
32+
source_dir: Real directory to mirror.
33+
virtual_prefix: Virtual FS prefix to write files under.
34+
exclude: Top-level names within source_dir to skip.
35+
"""
36+
import mkdocs_gen_files
37+
38+
exclude = exclude or set()
39+
40+
for source_file in source_dir.rglob("*"):
41+
if not source_file.is_file():
42+
continue
43+
44+
relative = source_file.relative_to(source_dir)
45+
46+
if relative.parts[0] in exclude:
47+
continue
48+
49+
virtual_path = f"{virtual_prefix}/{relative.as_posix()}"
50+
with mkdocs_gen_files.open(virtual_path, "wb") as fd:
51+
fd.write(source_file.read_bytes())
52+
53+
54+
def _run_from_mkdocs_gen_files() -> None:
55+
"""Run when this module is loaded by mkdocs-gen-files."""
56+
import mkdocs_gen_files
57+
58+
script_path = Path(__file__).resolve()
59+
repo_root = _repo_root_from_script(script_path)
60+
61+
# 1. readme_toplevel.md → virtual readme.md
62+
readme_source = repo_root / "docs_dev" / "readme_toplevel.md"
63+
if readme_source.exists():
64+
with mkdocs_gen_files.open("README.md", "wb") as fd:
65+
fd.write(readme_source.read_bytes())
66+
else:
67+
print(f"Warning: '{readme_source}' does not exist, skipping.")
68+
69+
# 2. docs/ → virtual user/
70+
docs_dir = repo_root / "docs"
71+
if docs_dir.exists():
72+
_mirror_into_virtual_fs(docs_dir, "user")
73+
else:
74+
print(f"Warning: '{docs_dir}' does not exist, skipping.")
75+
76+
# 3. docs_dev/ → virtual dev/ (with exclusions)
77+
docs_dev_dir = repo_root / "docs_dev"
78+
if docs_dev_dir.exists():
79+
_mirror_into_virtual_fs(docs_dev_dir, "dev", exclude=DOCS_DEV_EXCLUDE)
80+
else:
81+
print(f"Warning: '{docs_dev_dir}' does not exist, skipping.")
82+
83+
84+
if __name__ != "__main__":
85+
_run_from_mkdocs_gen_files()

mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ site_name: DUNE Run Control (drunc) Developer Documentation
33
repo_name: DUNE-DAQ/drunc
44
repo_url: https://github.com/DUNE-DAQ/drunc
55

6-
docs_dir: docs_dev
6+
docs_dir: docs_anchor
77

88
theme:
99
name: material
@@ -39,6 +39,7 @@ plugins:
3939
- gen-files:
4040
scripts:
4141
- docs_dev/utils/generate_logging_autodocs.py
42+
- docs_dev/utils/mirror_docs.py
4243
# - literate-nav:
4344
# nav_file: README.md
4445
# - section-index

0 commit comments

Comments
 (0)