]> unremediatedgender.space Git - An_Algorithmic_Lucidity.git/commitdiff
render {static} in Markdown alternatives
authorZack M. Davis <code@zackmdavis.net>
Sun, 4 Oct 2026 19:23:09 +0000 (12:23 -0700)
committerZack M. Davis <code@zackmdavis.net>
Sun, 4 Oct 2026 19:35:40 +0000 (12:35 -0700)
Opus 5.5 spotted this when previous Claudes didn't

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CLAUDE.md
pelicanconf.py

index 5f5d82677f2f850b42176b98495bfff2662826ca..beeb69f21cfaff2375b80d09acd334ff6788ddb0 100644 (file)
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -285,7 +285,7 @@ Two related wants, neither implemented: a "Discussion on Less Wrong" link on eac
 
 **Where the LW URL should live — leaning sidecar, undecided.** The obvious answer is a `Lesswrong:` line in the post header; Pelican supports arbitrary metadata with no config change (`readers.py:320` lowercases the key, `:341` returns a single-line value as a string, `:117` passes unknown names through), exposing `article.lesswrong`. The problem is sequencing: the LW URL doesn't exist until *after* publishing, so post-header metadata forces a second commit per post that touches the post file. A sidecar `slug → LW URL` JSON keeps the publish commit clean and lets updates batch — which matters beyond tidiness, since every push triggers a full rebuild and the site-wide 404 window described above. Read it once in `pelicanconf.py` and attach `article.lesswrong` the way `_prepare_markdown_mirrors` attaches `article.markdown_url`; warn on a key matching no post, since the sidecar loses the typo-safety of co-located metadata. Slugs are verified unique corpus-wide, so slug is a safe key. Third option: linkpost *before* pushing (the blog URL is predictable from date and filename), publish once with the field already filled — costs a window where the LW post points at a 404.
 
-**Gotcha either way:** `_write_markdown_mirrors` restates a **hardcoded** field list (Author, date, Category, Tags, Canonical URL), so a new field silently vanishes from the `.md` mirrors — i.e. the artifact that exists for LLM legibility — unless added there too. It also pipes the body through `_absolutize_site_links`, so anything else that reuses post bodies for off-site consumption wants the same treatment.
+**Gotcha either way:** `_write_markdown_mirrors` restates a **hardcoded** field list (Author, date, Category, Tags, Canonical URL), so a new field silently vanishes from the `.md` mirrors — i.e. the artifact that exists for LLM legibility — unless added there too. It also pipes the body through `_resolve_static_links` (Pelican only resolves `{static}` in the HTML it renders, not in raw source) and `_absolutize_site_links`, so anything else that reuses post bodies for off-site consumption wants the same treatment.
 
 **Link-rewriting script.** Key on slug, not whole-URL matching. Since 2026-08-07 the corpus is uniform — every internal link is root-relative `/blog/YYYY/Mon/slug/` (293 of them: 287 in published posts, 6 in drafts), with no absolute or legacy-numeric-month forms left, so the script only has one input shape to parse. Dispositions: mapped post → LW URL; unmapped post → absolutize; link with a `#fragment` → leave pointing home, since LW has no corresponding anchor and a wrong landing spot beats an off-site one; `/blog/` and `/blog/tag/...` → absolutize only; plus a self-link guard.
 
index 088f56d62ab917bc377cc1a7237129db025c7255..bfc2b9961820b1ee778f970131326c22604de01b 100644 (file)
@@ -171,6 +171,21 @@ def _absolutize_site_links(body):
         lambda m: m.group(1) + origin + m.group(2) + m.group(3), body)
 
 
+# Pelican rewrites {static}/path placeholders only in the HTML it renders; the
+# mirrors are copied from the raw source, so without this they'd carry the
+# literal placeholder. Resolve it the way Pelican does under the default
+# STATIC_URL = '{path}': SITEURL + '/' + path, which is absolute in a publish
+# build and root-relative ('/images/...') in a local one. Matches anywhere,
+# not just in ](...) -- raw-HTML <img src>, <a href>, <video poster>,
+# <source src> all use it too.
+_STATIC_PLACEHOLDER = _re.compile(r'\{static\}/')
+
+
+def _resolve_static_links(body):
+    return _STATIC_PLACEHOLDER.sub(
+        lambda m: _markdown_mirror_state['siteurl'] + '/', body)
+
+
 def _write_markdown_mirrors(pelican_obj):
     output_path = _markdown_mirror_state['output_path']
     if not output_path:
@@ -179,7 +194,7 @@ def _write_markdown_mirrors(pelican_obj):
         with open(article.source_path, encoding='utf-8') as f:
             source = f.read()
         _, _, body = source.partition('\n\n')
-        body = _absolutize_site_links(body)
+        body = _absolutize_site_links(_resolve_static_links(body))
         md_abspath = _os.path.join(output_path, article.markdown_url)
         _os.makedirs(_os.path.dirname(md_abspath), exist_ok=True)
         # The source file's own metadata block was just stripped off by the