Skip to content

Instantly share code, notes, and snippets.

@fishyer
Created August 27, 2022 20:03
Show Gist options
  • Save fishyer/6f284ba18ce18c65e21f2b7ad1affe99 to your computer and use it in GitHub Desktop.
Save fishyer/6f284ba18ce18c65e21f2b7ad1affe99 to your computer and use it in GitHub Desktop.
getDate
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