Skip to content

Commit d8b0476

Browse files
Merge pull request #32 from OpenScience-Collective/feature/oscar-docs
Add OSCAR docs tab (rendered from the oscar submodule)
2 parents 149e57d + 40afb3b commit d8b0476

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "osa"]
22
path = osa
33
url = https://github.com/OpenScience-Collective/osa.git
4+
[submodule "oscar"]
5+
path = oscar
6+
url = https://github.com/OpenScience-Collective/oscar.git

mkdocs.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ plugins:
6767
- minify:
6868
minify_html: true
6969
- section-index
70+
# OSCAR doctrine, rendered from the oscar/ submodule at build time.
71+
- gen-files:
72+
scripts:
73+
- scripts/gen_oscar.py
7074
# API Reference Generation
7175
# --------------------------
7276
# These plugins auto-generate API documentation from OSA source code.
@@ -186,3 +190,17 @@ nav:
186190
- OSA Platform Overview: osa/presentations/osa-platform.md
187191
- Development: osa/development.md
188192
- Version Management: osa/version-management.md
193+
- OSCAR:
194+
- oscar/index.md
195+
- Grounding: oscar/grounding.md
196+
- Principles: oscar/principles.md
197+
- Archetypes:
198+
- Website & docs sites: oscar/archetypes/website.md
199+
- Command-line tools: oscar/archetypes/cli.md
200+
- Libraries & toolboxes: oscar/archetypes/library.md
201+
- Web apps & APIs: oscar/archetypes/web-app-api.md
202+
- Data archives: oscar/archetypes/data-archive.md
203+
- Research lab sites: oscar/archetypes/lab-website.md
204+
- Standards & specs: oscar/archetypes/standard.md
205+
- Checklist: oscar/checklist.md
206+
- Templates & examples: https://github.com/OpenScience-Collective/oscar

oscar

Submodule oscar added at b17528a

scripts/gen_oscar.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Render the OSCAR doctrine into the docs site at build time.
2+
3+
The OSCAR doctrine lives in the OSCAR repo (added here as the ``oscar/``
4+
submodule), so it has a single source of truth. This mkdocs-gen-files script
5+
copies the markdown from ``oscar/docs/`` into the virtual site tree under
6+
``oscar/`` on every build, rewriting repo-relative links (to templates,
7+
examples, and the like) so they resolve to the OSCAR repo on GitHub.
8+
9+
Nothing is duplicated in git: edit the docs in the OSCAR repo, bump the
10+
submodule here, and docs.osc.earth reflects the change on the next build.
11+
"""
12+
13+
from __future__ import annotations
14+
15+
import re
16+
from pathlib import Path
17+
18+
import mkdocs_gen_files
19+
20+
SRC = Path("oscar/docs")
21+
REPO = "https://github.com/OpenScience-Collective/oscar"
22+
23+
# Links like ](../../templates/llms.txt) point at files that live in the OSCAR
24+
# repo, not the docs site. Rewrite any "up and out" link to a GitHub blob URL.
25+
_UP_AND_OUT = re.compile(r"\]\((?:\.\./)+([^)]+)\)")
26+
27+
28+
def rewrite_links(text: str) -> str:
29+
return _UP_AND_OUT.sub(lambda m: f"]({REPO}/blob/main/{m.group(1)})", text)
30+
31+
32+
if not SRC.is_dir():
33+
raise SystemExit(
34+
f"OSCAR docs not found at {SRC}. Initialise the submodule with: "
35+
"git submodule update --init oscar"
36+
)
37+
38+
for src in sorted(SRC.rglob("*.md")):
39+
rel = src.relative_to(SRC)
40+
dest = rel.with_name("index.md") if rel.name == "README.md" else rel
41+
out = (Path("oscar") / dest).as_posix()
42+
with mkdocs_gen_files.open(out, "w") as fh:
43+
fh.write(rewrite_links(src.read_text(encoding="utf-8")))
44+
mkdocs_gen_files.set_edit_path(out, f"{REPO}/edit/main/docs/{rel.as_posix()}")

0 commit comments

Comments
 (0)