Commit de23fd8882
Unregistered key
Layout: unified · split
build.py +21 −1
| @@ -272,7 +272,27 @@ def copy_org_sources(content_dir="./content", build_dir="./.build/org"): | ||
| 272 | 272 | print(f"Copying org sources: {content_dir} → {build_dir}") |
| 273 | 273 | if os.path.exists(build_dir): |
| 274 | 274 | shutil.rmtree(build_dir) |
| 275 | shutil.copytree(content_dir, build_dir) | |
| 275 | ||
| 276 | slug_pattern = re.compile(r"^#\+slug:\s*(.+)$", re.IGNORECASE) | |
| 277 | ||
| 278 | for src_path in Path(content_dir).rglob("*.org"): | |
| 279 | rel_dir = src_path.parent.relative_to(content_dir) | |
| 280 | dest_dir = Path(build_dir) / rel_dir | |
| 281 | dest_dir.mkdir(parents=True, exist_ok=True) | |
| 282 | ||
| 283 | # Try to extract slug from file headers | |
| 284 | slug = None | |
| 285 | with src_path.open("r", encoding="utf-8") as f: | |
| 286 | for line in f: | |
| 287 | m = slug_pattern.match(line) | |
| 288 | if m: | |
| 289 | slug = m.group(1).strip() | |
| 290 | break | |
| 291 | ||
| 292 | dest_name = f"{slug}.org" if slug else src_path.name | |
| 293 | shutil.copy2(src_path, dest_dir / dest_name) | |
| 294 | if slug: | |
| 295 | print(f" {src_path.name} → {dest_name}") | |
| 276 | 296 | |
| 277 | 297 | |
| 278 | 298 | def generate_sitemap(build_dir=".build", base_url="https://cleberg.net"): |