-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Type error with YAML dates in frontmatter #49
Conversation
When valid YAML dates or times are added to the page frontmatter, the YAML parser will already convert them to datetime.date or datetime.datetime objects. Example: --- date: 2023-04-12 --- This resulted in #strptime raising a TypeError because datetime.date isn't a string. This commit changes the plugin code to always accept a native datetime.date or datetime.datetime, even if meta_time_format is not set, and handle them without string parsing. Close liang2kl#48
5325de3
to
e07b738
Compare
mkdocs_blogging_plugin/plugin.py
Outdated
timestamp = self._parse_time(page.meta["date"]) | ||
if not timestamp: | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If time
is included in the page meta but is not a date time, and meta_time_format
is not set, this will end up with timestamp = None
.
For example:
---
time: 5 minutes
date: 2024-04-12
---
The time
meta could be meant for another plugin.
Using is None
would try with "date"
if "time"
is present but cannot be parsed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I understand. Thank you for the explanation.
1460a4f
to
e07b738
Compare
By the way, could you please update the docs? The related stuff should be in the "Global Settings" section of |
I added an extra test about the fallback if
I've added a note. |
When valid YAML dates or times are added to the page frontmatter, the YAML parser will already convert them to
datetime.date
ordatetime.datetime
objects.Example:
This resulted in #strptime raising a
TypeError
becausedatetime.date
isn't a string. This commit changes the plugin code to always accept a nativedatetime.date
ordatetime.datetime
, even ifmeta_time_format
is not set, and handle them without string parsing.Close #48