From 4a9b2bf1b3e0b48ce963c73d0809873f14638e15 Mon Sep 17 00:00:00 2001 From: Gio Date: Mon, 27 Apr 2026 00:18:56 -0500 Subject: [PATCH 1/4] Feature: Simulate `Meta` attribute population --- pelican/plugins/yaml_metadata/yaml_metadata.py | 16 +++++++++++++++- pyproject.toml | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pelican/plugins/yaml_metadata/yaml_metadata.py b/pelican/plugins/yaml_metadata/yaml_metadata.py index 44bf908..c114c03 100644 --- a/pelican/plugins/yaml_metadata/yaml_metadata.py +++ b/pelican/plugins/yaml_metadata/yaml_metadata.py @@ -98,9 +98,23 @@ def read(self, source_path): ) return super().read(source_path) + metadata = self._load_yaml_metadata(m.group("metadata"), source_path) + + # Simulate markdown.extensions.meta's behavior + # of writing the markdown object's Meta attribiute + # Note this is not 1:1 (datetimes are reformatted) + self._md.Meta = { + k: ( + [str(i) for i in v] + if isinstance(v, list) else + [str(v)] + ) + for k, v in metadata.items() + } + return ( self._md.reset().convert(m.group("content")), - self._load_yaml_metadata(m.group("metadata"), source_path), + metadata, ) def _load_yaml_metadata(self, text, source_path): diff --git a/pyproject.toml b/pyproject.toml index 84f00fd..21e1c3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pelican-yaml-metadata" -version = "2.1.2" +version = "2.2.0" description = "Pelican plugin for YAML-formatted Markdown metadata headers" authors = [ {name = "Carey Metcalfe", email = "carey@cmetcalfe.ca"}, From be72bff568a5e08576124bf0b312a416e8cf5b11 Mon Sep 17 00:00:00 2001 From: Gio Date: Tue, 28 Apr 2026 15:51:35 -0500 Subject: [PATCH 2/4] Revert version increment for autopub --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 21e1c3b..84f00fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pelican-yaml-metadata" -version = "2.2.0" +version = "2.1.2" description = "Pelican plugin for YAML-formatted Markdown metadata headers" authors = [ {name = "Carey Metcalfe", email = "carey@cmetcalfe.ca"}, From f6b734cea516b018499446b8fc482431ac58619a Mon Sep 17 00:00:00 2001 From: Gio Date: Tue, 28 Apr 2026 16:07:33 -0500 Subject: [PATCH 3/4] Replace multiline comprehension with helper function --- pelican/plugins/yaml_metadata/yaml_metadata.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pelican/plugins/yaml_metadata/yaml_metadata.py b/pelican/plugins/yaml_metadata/yaml_metadata.py index c114c03..009a144 100644 --- a/pelican/plugins/yaml_metadata/yaml_metadata.py +++ b/pelican/plugins/yaml_metadata/yaml_metadata.py @@ -67,6 +67,12 @@ def _parse_date(obj): return get_date(str(obj).strip().replace("_", " ")) +def _convert_py_to_meta(obj) -> list[str]: + # Convert a yaml-parsed python object to meta's list of strings + if isinstance(obj, list): + return [str(i) for i in obj] + else: + return [str(obj)] class YAMLMetadataReader(MarkdownReader): """Reader for Markdown files with YAML metadata.""" @@ -103,12 +109,8 @@ def read(self, source_path): # Simulate markdown.extensions.meta's behavior # of writing the markdown object's Meta attribiute # Note this is not 1:1 (datetimes are reformatted) - self._md.Meta = { - k: ( - [str(i) for i in v] - if isinstance(v, list) else - [str(v)] - ) + self._md.Meta = { # type: ignore + k: _convert_py_to_meta(v) for k, v in metadata.items() } From 8abd539d5655ed3c96f83b2e6254a919a627cf89 Mon Sep 17 00:00:00 2001 From: Gio Date: Sun, 10 May 2026 10:03:35 -0500 Subject: [PATCH 4/4] Uglify list comprehension --- pelican/plugins/yaml_metadata/yaml_metadata.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) mode change 100644 => 100755 pelican/plugins/yaml_metadata/yaml_metadata.py diff --git a/pelican/plugins/yaml_metadata/yaml_metadata.py b/pelican/plugins/yaml_metadata/yaml_metadata.py old mode 100644 new mode 100755 index 009a144..9463e39 --- a/pelican/plugins/yaml_metadata/yaml_metadata.py +++ b/pelican/plugins/yaml_metadata/yaml_metadata.py @@ -67,6 +67,7 @@ def _parse_date(obj): return get_date(str(obj).strip().replace("_", " ")) + def _convert_py_to_meta(obj) -> list[str]: # Convert a yaml-parsed python object to meta's list of strings if isinstance(obj, list): @@ -74,6 +75,7 @@ def _convert_py_to_meta(obj) -> list[str]: else: return [str(obj)] + class YAMLMetadataReader(MarkdownReader): """Reader for Markdown files with YAML metadata.""" @@ -109,9 +111,8 @@ def read(self, source_path): # Simulate markdown.extensions.meta's behavior # of writing the markdown object's Meta attribiute # Note this is not 1:1 (datetimes are reformatted) - self._md.Meta = { # type: ignore - k: _convert_py_to_meta(v) - for k, v in metadata.items() + self._md.Meta = { # type: ignore + k: _convert_py_to_meta(v) for k, v in metadata.items() } return (