Commit a19b44866f
Verified · cmc
Layout: unified · split
build.py +21
| @@ -317,6 +317,26 @@ def minify_html(src_html, dest_html): | ||
| 317 | 317 | sys.exit(1) |
| 318 | 318 | |
| 319 | 319 | |
| 320 | def rewrite_img_urls(build_dir=".build"): | |
| 321 | """ | |
| 322 | Rewrite absolute img.cleberg.net URLs to root-relative /img/ paths so the | |
| 323 | onion serves images from its own origin instead of fetching them off-onion. | |
| 324 | Production only: dev builds keep the absolute URLs so local previews still | |
| 325 | load images from the live image host. | |
| 326 | ||
| 327 | Requires the server to serve /var/www/img/ at /img/ on the cleberg.net vhost | |
| 328 | (e.g. `ln -s /var/www/img /var/www/cleberg.net/img`). | |
| 329 | """ | |
| 330 | count = 0 | |
| 331 | for html in Path(build_dir).rglob("*.html"): | |
| 332 | text = html.read_text(encoding="utf-8") | |
| 333 | new_text = text.replace("https://img.cleberg.net/", "/img/") | |
| 334 | if new_text != text: | |
| 335 | count += text.count("https://img.cleberg.net/") | |
| 336 | html.write_text(new_text, encoding="utf-8") | |
| 337 | print(f"Rewrote {count} img.cleberg.net references to /img/") | |
| 338 | ||
| 339 | ||
| 320 | 340 | def run_emacs_publish(dev_mode=True): |
| 321 | 341 | mode = "development" if dev_mode else "production" |
| 322 | 342 | print(f"Running Emacs publish script ({mode})...") |
| @@ -579,6 +599,7 @@ def main(): | ||
| 579 | 599 | update_marked_section(html_snippet) |
| 580 | 600 | inject_blog_year_separators() |
| 581 | 601 | generate_tags_page() |
| 602 | rewrite_img_urls(build_dir) | |
| 582 | 603 | # minify_html("./.build/index.html", "./.build/index.html") |
| 583 | 604 | generate_sitemap() |
| 584 | 605 | if deploy: |