Commit a19b44866f

a19b44866fc5917eb5001f856e29d12f773e36fa

parent: 681a290e9e

Verified · cmc

cmc <hello@cleberg.net> · 2026-08-03 20:16 UTC

serve blog images from root-relative /img/ path

Rewrite absolute img.cleberg.net URLs to /img/ in production builds so the
onion serves images from its own origin instead of fetching them off-onion.
Dev builds keep the absolute URLs so local previews still load images.

Requires the server to serve /var/www/img/ at /img/ on the cleberg.net
vhost (ln -s /var/www/img /var/www/cleberg.net/img).

Layout: unified · split

build.py +21
@@ -317,6 +317,26 @@ def minify_html(src_html, dest_html):
317317 sys.exit(1)
318318
319319
320def 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
320340def run_emacs_publish(dev_mode=True):
321341 mode = "development" if dev_mode else "production"
322342 print(f"Running Emacs publish script ({mode})...")
@@ -579,6 +599,7 @@ def main():
579599 update_marked_section(html_snippet)
580600 inject_blog_year_separators()
581601 generate_tags_page()
602 rewrite_img_urls(build_dir)
582603 # minify_html("./.build/index.html", "./.build/index.html")
583604 generate_sitemap()
584605 if deploy: