frontmatter fix about 'created' field

This commit is contained in:
faildev_mode 2023-05-29 18:19:34 +02:00
parent 185373699b
commit c5cdcc42f8
No known key found for this signature in database
GPG Key ID: 70845C70C0F5E205
1 changed files with 9 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import sys
import configparser
from fnmatch import fnmatch
import frontmatter # from package python-frontmatter
import datetime
def link_this(src: str, dest: str):
"""Creates symlink to source at destination
@ -109,7 +110,14 @@ if __name__ == '__main__':
# load content file
with open('content/'+path) as fp:
content_data = fp.read()
frontmatter_data, content = frontmatter.parse(fp.read())
if 'created' in frontmatter_data:
# frontmatter produces date objects if created field is in format yyyy-mm-dd
# if it contains time as in ISO 8601, we want to convert it to datetime
# https://en.wikipedia.org/wiki/ISO_8601
if type(frontmatter_data['created']) == str:
frontmatter_data['created'] = datetime.datetime.fromisoformat(frontmatter_data['created'])
# load template
if template := template_for(path):