From e8cfe8445e8dedf25a65bf814016f465a70f791e Mon Sep 17 00:00:00 2001 From: ousttrue Date: Sun, 2 Jan 2022 06:57:14 +0900 Subject: [PATCH] Fix tags field for myst_parser (#119) --- ablog/post.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ablog/post.py b/ablog/post.py index 67d298bd..a1149643 100644 --- a/ablog/post.py +++ b/ablog/post.py @@ -173,6 +173,16 @@ def apply(self): # Pull the metadata for the page to check if it is a blog post metadata = {fn.children[0].astext(): fn.children[1].astext() for fn in docinfo.traverse(nodes.field)} + tags = metadata.get("tags") + if isinstance(tags, str): + # myst_parser store front-matter field to TextNode in dict_to_fm_field_list. + # like ["a", "b", "c"] + # remove [] and quote + try: + tags = eval(tags) + metadata["tags"] = ",".join(tags) + except Exception: + logging.warning(f"fail to eval tags: {tags}") if docinfo.traverse(nodes.author): metadata["author"] = list(docinfo.traverse(nodes.author))[0].astext() # These two fields are special-cased in docutils