Commit 6e2c9856b9

6e2c9856b98faa2fc79ae12883ddf5acd1098f8e

parent: c31e8bfa41

Verified · cmc

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

fix malformed image URL and harden img rewrite

Correct a https:/// typo in the tumblr post org source that produced a
404ing cross-origin image URL. Because the extra slash meant the string
no longer matched, rewrite_img_urls() skipped it and shipped the broken
URL. Make the rewrite pattern tolerate stray slashes so a source typo
can't silently pass through un-rewritten again.

Layout: unified · split

build.py +8 −3
@@ -326,13 +326,18 @@ def rewrite_img_urls(build_dir=".build"):
326326
327327 Requires the server to serve /var/www/img/ at /img/ on the cleberg.net vhost
328328 (e.g. `ln -s /var/www/img /var/www/cleberg.net/img`).
329
330 The pattern tolerates a stray number of slashes after the scheme
331 (https:/img, https:///img, ...) so a typo in the org source can't silently
332 slip through un-rewritten and ship a broken cross-origin URL.
329333 """
334 pattern = re.compile(r"https:/+img\.cleberg\.net/")
330335 count = 0
331336 for html in Path(build_dir).rglob("*.html"):
332337 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/")
338 new_text, n = pattern.subn("/img/", text)
339 if n:
340 count += n
336341 html.write_text(new_text, encoding="utf-8")
337342 print(f"Rewrote {count} img.cleberg.net references to /img/")
338343
content/blog/2023-01-05-mass-unlike-tumblr-posts.org +1 −1
@@ -58,7 +58,7 @@ this (this is in Firefox, Chromium should be similar):
5858
5959#+caption: Firefox Dev Tools
6060#+attr_html: :alt Firefox Dev Tools' Console tab will allow you to paste this command.
61[[https:///img.cleberg.net/blog/20230105-mass-unlike-tumblr-posts/dev_console.webp]]
61[[https://img.cleberg.net/blog/20230105-mass-unlike-tumblr-posts/dev_console.webp]]
6262
6363All you need to do is paste the following snippet into the dev console.
6464This code will collect all unlike buttons (=elements=) and then click