Repository navigation
Optional items in FILENAME_METADATA expression. - #2117
Merged
justinmayer merged 1 commit intoMar 20, 2017
Merged
Conversation
avaris
reviewed
Mar 15, 2017
| for k, v in match.groupdict().items(): | ||
| k = k.lower() # metadata must be lowercase | ||
| if k not in metadata: | ||
| if k not in metadata and v is not None: |
Member
There was a problem hiding this comment.
Not that big of a deal but I'd prefer switching the comparison order for performance reasons. Comparison to None would be faster and should short-circuit earlier:
if v is not None and k not in metadata:
Contributor
Author
There was a problem hiding this comment.
I agree, that makes sense. I'll swap the order and replace this commit.
This is relevant when using optional items in the expression. E.g. if an optional captured group is not matched, the result of `match.groupdict()` contains the captured group with value `None`.
timwienk
force-pushed
the
fix-none-filename-metadata
branch
from
March 15, 2017 16:09
97dafde to
4917b86
Compare
Member
Member
|
You are my new hero, Tim. Why, you ask?
Thank you for fulfilling every project maintainer's dream. 😃 👍 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To keep my articles somewhat organised, I like to add the date to the filename of the article and extract it using
FILENAME_METADATA. However, for pages I don't quite want to do that. I used to use a simple plugin to set the date based on mtime, but sinceDEFAULT_DATE = 'fs'uses mtime now (since December 2016) instead of ctime, this option is great for this.However, things go wrong when making the date capture group optional in the
FILENAME_METADATAexpression. Previously I monkey patched thepelican.readers.parse_path_metadatafunction, but since theDEFAULT_DATE = 'fs'option changed, I figured it's a good idea to try and get this part of the date configuration sorted within Pelican itself as well.Case:
files:
content/index.mdcontent/articles/2017-03-11.interesting-article.mdpelicanconf.py:
Error:
The regex match result for the "date" group is
Noneforcontent/index.md. When Pelican attempts to process the date,None.replace()throws anAttributeError: 'NoneType' object has no attribute 'replace'.Solution:
In addition to checking
if k not in metadatawhen applying the matched filename metadata, also checkif v is not None.Please see the commit in the pull request for the actual change + added tests.