"""Copy Hugo-rendered HTML output into the repo public directory.
Run after:
1. python skills-scripts/sync_content_to_hugo.py
2. cd hugo-html-builder && hugo --cleanDestinationDir
3. python skills-scripts/build_ai_index.py
4. python skills-scripts/build_discovery_files.py
This script copies files from hugo-html-builder/public into public while
preserving repo-level discovery files and the Poppy manifest generated outside Hugo.
"""
from __future__ import annotations
import shutil
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
HUGO_PUBLIC = REPO_ROOT / "hugo-html-builder" / "public"
PUBLIC_ROOT = REPO_ROOT / "public"
PRESERVE_AT_PUBLIC_ROOT = {
"robots.txt",
"sitemap.xml",
"llms.txt",
"agents.md",
"skills.md",
"ai-index.json",
}
def should_preserve(relative_path: Path) -> bool:
if relative_path.as_posix() == ".well-known/poppy.json":
return True
return len(relative_path.parts) == 1 and relative_path.name in PRESERVE_AT_PUBLIC_ROOT
def copy_hugo_output() -> tuple[int, list[str]]:
if not HUGO_PUBLIC.exists():
raise FileNotFoundError(f"Missing Hugo output directory: {HUGO_PUBLIC}")
copied = 0
skipped: list[str] = []
for source in HUGO_PUBLIC.rglob("*"):
if source.is_dir():
continue
relative = source.relative_to(HUGO_PUBLIC)
if should_preserve(relative):
skipped.append(relative.as_posix())
continue
target = PUBLIC_ROOT / relative
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, target)
copied += 1
return copied, skipped
def main() -> None:
copied, skipped = copy_hugo_output()
print(f"Copied {copied} Hugo output files into {PUBLIC_ROOT}")
if skipped:
print("Preserved discovery files:")
for path in skipped:
print(f"- {path}")
if __name__ == "__main__":
main()