From 8f349e70609a68eeb6a659f37e132dea86972648 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sat, 25 Jul 2026 15:43:16 -0700 Subject: [PATCH] include author/category/tags in Markdown alternative --- pelicanconf.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pelicanconf.py b/pelicanconf.py index c8ef7c0..ac2654e 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -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()) -- 2.53.0