diff options
| author | Christian Cleberg <[email protected]> | 2026-08-03 15:41:22 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-08-03 15:41:22 -0500 |
| commit | 6e2c9856b98faa2fc79ae12883ddf5acd1098f8e (patch) | |
| tree | 213d5300dc8b4dfce347d98fa955d82ab2b6845a /build.py | |
| parent | c31e8bfa414cdc1fe035a5d6d55a477f77525dd7 (diff) | |
| download | cleberg.net-6e2c9856b98faa2fc79ae12883ddf5acd1098f8e.tar.gz cleberg.net-6e2c9856b98faa2fc79ae12883ddf5acd1098f8e.tar.bz2 cleberg.net-6e2c9856b98faa2fc79ae12883ddf5acd1098f8e.zip | |
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.
Diffstat (limited to 'build.py')
| -rwxr-xr-x | build.py | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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/") |
