Skip to content

Commit

Permalink
Fix tags field for myst_parser (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue authored Jan 1, 2022
1 parent 2798ed1 commit e8cfe84
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ablog/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8cfe84

Please sign in to comment.