Created
August 27, 2022 20:03
-
-
Save fishyer/6f284ba18ce18c65e21f2b7ad1affe99 to your computer and use it in GitHub Desktop.
getDate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getDate(md_file): | |
with open(md_file) as f: | |
md = frontmatter.load(f) | |
dt = md.metadata['date'] | |
if type(dt) == str: | |
# toml 格式下date被识别为字符串 | |
return dateutil.parser.parse(dt).date() | |
else: | |
# yaml 格式下date被识别为datetime,直接返回 | |
return dt.date() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment