Authored-By: OpenAI (GPT-5) <noreply@openai.com>
This commit is contained in:
+26
-21
@@ -1,25 +1,25 @@
|
||||
"""Build phase — content prep for static-content sites."""
|
||||
"""Build each declared static-content artifact independently."""
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from utils import EXCLUDE_FILES, env, parse_site_yaml, run
|
||||
from utils import EXCLUDE_FILES, env, parse_site_yaml, run, validate_artifact_inputs
|
||||
|
||||
|
||||
def build_static(site_dir, cfg):
|
||||
build_dir = site_dir / "build"
|
||||
html_dir = build_dir / "html"
|
||||
def build_artifact(site_dir, artifact):
|
||||
html_dir = site_dir / artifact["build_dir"]
|
||||
if html_dir.parent.exists():
|
||||
shutil.rmtree(html_dir.parent)
|
||||
|
||||
if build_dir.exists():
|
||||
shutil.rmtree(build_dir)
|
||||
|
||||
content_dir = cfg["content_dir"]
|
||||
content_dir = artifact["content_dir"]
|
||||
src = site_dir / content_dir if content_dir else site_dir
|
||||
if not src.exists():
|
||||
raise FileNotFoundError(f"artifact {artifact['name']} content_dir not found: {src}")
|
||||
|
||||
if cfg["type"] == "static":
|
||||
print(f"Copying static content from {src}")
|
||||
if artifact["type"] == "static":
|
||||
print(f"Copying artifact {artifact['name']} from {src}")
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp) / "html"
|
||||
shutil.copytree(src, tmp_path, dirs_exist_ok=True)
|
||||
@@ -29,18 +29,18 @@ def build_static(site_dir, cfg):
|
||||
shutil.rmtree(p)
|
||||
elif p.exists():
|
||||
p.unlink()
|
||||
build_dir.mkdir(parents=True)
|
||||
html_dir.parent.mkdir(parents=True)
|
||||
shutil.move(str(tmp_path), str(html_dir))
|
||||
|
||||
elif cfg["type"] == "hugo":
|
||||
print(f"Building Hugo site from {src}")
|
||||
run(f"hugo --source {src} --destination {html_dir}")
|
||||
elif artifact["type"] == "hugo":
|
||||
print(f"Building Hugo artifact {artifact['name']} from {src}")
|
||||
run(["hugo", "--source", str(src), "--destination", str(html_dir)])
|
||||
|
||||
elif cfg["type"] == "mkdocs":
|
||||
print(f"Building MkDocs site from {src}")
|
||||
run(f"cd {src} && mkdocs build -d {html_dir}")
|
||||
elif artifact["type"] == "mkdocs":
|
||||
print(f"Building MkDocs artifact {artifact['name']} from {src}")
|
||||
run(["mkdocs", "build", "-d", str(html_dir)], cwd=src)
|
||||
|
||||
if cfg.get("tidy", True):
|
||||
if artifact["tidy"]:
|
||||
print("Running tidy on HTML files...")
|
||||
for html_file in html_dir.rglob("*.html"):
|
||||
subprocess.run(
|
||||
@@ -51,7 +51,9 @@ def build_static(site_dir, cfg):
|
||||
check=False,
|
||||
)
|
||||
|
||||
print(f"Build complete — content at {html_dir}")
|
||||
if not any(path.is_file() for path in html_dir.rglob("*")):
|
||||
raise FileNotFoundError(f"artifact {artifact['name']} produced no files in {html_dir}")
|
||||
print(f"Artifact {artifact['name']} complete — content at {html_dir}")
|
||||
|
||||
|
||||
def cmd_build():
|
||||
@@ -62,4 +64,7 @@ def cmd_build():
|
||||
print("Site disabled — skipping build")
|
||||
return
|
||||
|
||||
build_static(site_dir, cfg)
|
||||
validate_artifact_inputs(site_dir, cfg)
|
||||
|
||||
for artifact in cfg["artifacts"]:
|
||||
build_artifact(site_dir, artifact)
|
||||
|
||||
Reference in New Issue
Block a user