diff options
| author | Christian Cleberg <[email protected]> | 2026-08-03 15:16:23 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-08-03 15:16:23 -0500 |
| commit | a19b44866fc5917eb5001f856e29d12f773e36fa (patch) | |
| tree | 01d716389d7c085772b8865a3989a954f84a2376 | |
| parent | 681a290e9ec232296cafee94ac76aa269a11b5bd (diff) | |
| download | cleberg.net-a19b44866fc5917eb5001f856e29d12f773e36fa.tar.gz cleberg.net-a19b44866fc5917eb5001f856e29d12f773e36fa.tar.bz2 cleberg.net-a19b44866fc5917eb5001f856e29d12f773e36fa.zip | |
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).
| -rwxr-xr-x | build.py | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -317,6 +317,26 @@ def minify_html(src_html, dest_html): sys.exit(1) +def rewrite_img_urls(build_dir=".build"): + """ + Rewrite absolute img.cleberg.net URLs to root-relative /img/ paths so the + onion serves images from its own origin instead of fetching them off-onion. + Production only: dev builds keep the absolute URLs so local previews still + load images from the live image host. + + Requires the server to serve /var/www/img/ at /img/ on the cleberg.net vhost + (e.g. `ln -s /var/www/img /var/www/cleberg.net/img`). + """ + count = 0 + for html in Path(build_dir).rglob("*.html"): + text = html.read_text(encoding="utf-8") + new_text = text.replace("https://img.cleberg.net/", "/img/") + if new_text != text: + count += text.count("https://img.cleberg.net/") + html.write_text(new_text, encoding="utf-8") + print(f"Rewrote {count} img.cleberg.net references to /img/") + + def run_emacs_publish(dev_mode=True): mode = "development" if dev_mode else "production" print(f"Running Emacs publish script ({mode})...") @@ -579,6 +599,7 @@ def main(): update_marked_section(html_snippet) inject_blog_year_separators() generate_tags_page() + rewrite_img_urls(build_dir) # minify_html("./.build/index.html", "./.build/index.html") generate_sitemap() if deploy: |
