diff --git a/docs/hooks.py b/docs/hooks.py index 159c5328..a888b352 100644 --- a/docs/hooks.py +++ b/docs/hooks.py @@ -6,16 +6,11 @@ sentence is dropped from the README body since the example is shown inline. """ -import atexit import re -import shutil -import tempfile from pathlib import Path from mkdocs.structure.files import File -_tmp_dir: str | None = None - _WORKFLOWS_DIR = "gh-agent-workflows" _DOCS_DEST = "workflows/gh-agent-workflows" _GITHUB_REPO = "https://github.com/elastic/ai-github-actions" @@ -114,15 +109,6 @@ def _generate_page(workflow_dir: Path) -> str: return f"{readme.rstrip()}\n\n## Example Workflow\n\n```yaml\n{example.rstrip()}\n```\n" -def on_pre_build(config): - """Create a fresh temp directory for generated pages before each build.""" - global _tmp_dir - if _tmp_dir is not None: - shutil.rmtree(_tmp_dir, ignore_errors=True) - _tmp_dir = tempfile.mkdtemp(prefix="mkdocs_gh_agent_") - atexit.register(shutil.rmtree, _tmp_dir, True) - - def on_files(files, config): repo_root = Path(config["docs_dir"]).parent workflows_path = repo_root / _WORKFLOWS_DIR @@ -136,17 +122,6 @@ def on_files(files, config): page_content = _generate_page(workflow_dir) rel_path = f"{_DOCS_DEST}/{workflow_dir.name}.md" - tmp_file = Path(_tmp_dir) / rel_path - tmp_file.parent.mkdir(parents=True, exist_ok=True) - tmp_file.write_text(page_content, encoding="utf-8") - - files.append( - File( - path=rel_path, - src_dir=_tmp_dir, - dest_dir=config["site_dir"], - use_directory_urls=config.get("use_directory_urls", True), - ) - ) + files.append(File.generated(config, rel_path, content=page_content)) return files