-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.py
More file actions
59 lines (47 loc) · 1.78 KB
/
Copy pathhooks.py
File metadata and controls
59 lines (47 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""MkDocs hooks for DataFlow docs site."""
from __future__ import annotations
import shutil
from pathlib import Path
def on_post_build(config, **kwargs) -> None:
"""Post-build: ensure llms.txt at site root and publish schemas/."""
site_dir = Path(config["site_dir"])
docs_dir = Path(config["docs_dir"])
_ensure_llms_txt(site_dir, docs_dir)
_copy_schemas(site_dir, docs_dir)
def _ensure_llms_txt(site_dir: Path, docs_dir: Path) -> None:
"""Ensure site/llms.txt exists for LLM crawlers.
With mkdocs-static-i18n (en = default), ``docs/en/llms.txt`` is already
copied to the site root. This hook is a safety net if the file lands only
under ``en/`` or needs to be copied from the docs source.
"""
dest = site_dir / "llms.txt"
if dest.is_file():
return
for candidate in (
site_dir / "en" / "llms.txt",
docs_dir / "en" / "llms.txt",
docs_dir / "llms.txt",
):
if candidate.is_file():
shutil.copy2(candidate, dest)
return
def _schemas_source(docs_dir: Path) -> Path | None:
"""Resolve monorepo schemas/ relative to MkDocs docs_dir (docs/docs)."""
for candidate in (
docs_dir.parent.parent / "schemas", # docs/docs → repo/schemas
docs_dir.parent / "schemas", # docs → docs/schemas
Path.cwd() / "schemas",
Path.cwd().parent / "schemas",
):
if (candidate / "catalog.json").is_file():
return candidate
return None
def _copy_schemas(site_dir: Path, docs_dir: Path) -> None:
"""Copy machine-readable schemas into site/schemas for stable URLs."""
src = _schemas_source(docs_dir)
if src is None:
return
dest = site_dir / "schemas"
if dest.exists():
shutil.rmtree(dest)
shutil.copytree(src, dest)