]> zackmdavis.net Git - An_Algorithmic_Lucidity.git/commitdiff
include author/category/tags in Markdown alternative
authorZack M. Davis <code@zackmdavis.net>
Sat, 25 Jul 2026 22:43:16 +0000 (15:43 -0700)
committerZack M. Davis <code@zackmdavis.net>
Sat, 25 Jul 2026 22:43:16 +0000 (15:43 -0700)
pelicanconf.py

index c8ef7c05337d1501ee9f1d33c2afe3cff7881b40..ac2654e44c489696e83507f9c6a5139110adeca5 100644 (file)
@@ -145,11 +145,25 @@ def _write_markdown_mirrors(pelican_obj):
         _, _, body = source.partition('\n\n')
         md_abspath = _os.path.join(output_path, article.markdown_url)
         _os.makedirs(_os.path.dirname(md_abspath), exist_ok=True)
-        header = (
-            f"# {article.title}\n\n"
-            f"Originally published: {article.date.strftime('%Y-%m-%d')}\n"
-            f"Canonical URL: {_canonical_url(article.url)}\n\n"
-        )
+        # The source file's own metadata block was just stripped off by the
+        # partition() above, so restate it here in a form a reader of the bare
+        # .md can use: these mirrors exist precisely to be read detached from
+        # the site, where category and tags are the only signal of what
+        # neighborhood a post belongs to. Author comes from the AUTHOR setting
+        # (no post sets it per-article), and category is always present, but
+        # both are fetched defensively so an untagged or category-less post
+        # can't break the build.
+        meta = []
+        if getattr(article, 'author', None):
+            meta.append(f"Author: {article.author.name}")
+        meta.append(f"Originally published: {article.date.strftime('%Y-%m-%d')}")
+        if getattr(article, 'category', None):
+            meta.append(f"Category: {article.category.name}")
+        tags = getattr(article, 'tags', None)
+        if tags:
+            meta.append("Tags: " + ", ".join(tag.name for tag in tags))
+        meta.append(f"Canonical URL: {_canonical_url(article.url)}")
+        header = "# {}\n\n{}\n\n".format(article.title, "\n".join(meta))
         with open(md_abspath, 'w', encoding='utf-8') as f:
             f.write(header)
             f.write(body.strip())