cmc/cleberg.net

My personal web garden & blog.

clone: git clone https://gitbay.org/cmc/cleberg.net.git

6e2c9856b98faa2fc79ae12883ddf5acd1098f8e

verified · cmc

author: Christian Cleberg <hello@cleberg.net> · 2026-08-03T20:41:22Z

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.
 build.py                                             | 11 ++++++++---
 content/blog/2023-01-05-mass-unlike-tumblr-posts.org |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/build.py b/build.py
index 28af6ec..771c406 100755
--- a/build.py
+++ b/build.py
@@ -326,13 +326,18 @@ def rewrite_img_urls(build_dir=".build"):
 
     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`).
+
+    The pattern tolerates a stray number of slashes after the scheme
+    (https:/img, https:///img, ...) so a typo in the org source can't silently
+    slip through un-rewritten and ship a broken cross-origin URL.
     """
+    pattern = re.compile(r"https:/+img\.cleberg\.net/")
     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/")
+        new_text, n = pattern.subn("/img/", text)
+        if n:
+            count += n
             html.write_text(new_text, encoding="utf-8")
     print(f"Rewrote {count} img.cleberg.net references to /img/")
 
diff --git a/content/blog/2023-01-05-mass-unlike-tumblr-posts.org b/content/blog/2023-01-05-mass-unlike-tumblr-posts.org
index c3ce8fa..6b4261f 100644
--- a/content/blog/2023-01-05-mass-unlike-tumblr-posts.org
+++ b/content/blog/2023-01-05-mass-unlike-tumblr-posts.org
@@ -58,7 +58,7 @@ this (this is in Firefox, Chromium should be similar):
 
 #+caption: Firefox Dev Tools
 #+attr_html: :alt Firefox Dev Tools' Console tab will allow you to paste this command.
-[[https:///img.cleberg.net/blog/20230105-mass-unlike-tumblr-posts/dev_console.webp]]
+[[https://img.cleberg.net/blog/20230105-mass-unlike-tumblr-posts/dev_console.webp]]
 
 All you need to do is paste the following snippet into the dev console.
 This code will collect all unlike buttons (=elements=) and then click