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
Path metadata issues with date, category, lang, slug (when not mandatory) #1128
Comments
I would like to know if any of this behavior has been tackled since @fvsch brought it up. For a project I also would like to extract the metadata. In more detail I would like to extract If the metadata |
We can skip setting empty/ From least important to most important:
Any thoughts? cc: @justinmayer @ametaireau @smartass101 [*] Also on a related note: we might consider deprecating these and go with the single setting |
I've been avoiding the problem of regex named groups being set to
Notice how the matching pattern is within that inner group? If no text matches, the named group will still have a value: an empty string. My workaround means making regular expressions a bit more complex than they should have to be, though, and it isn't exactly obvious. It would nice if Pelican did something more intuitive here. Maybe replacing |
Slug can now come from filename with |
This issue report comprises serveral problems:
|
I'm trying to fix the |
I have a question about the behavior of Given the following setup: pelicanconf.py USE_FOLDER_AS_CATEGORY = True
PATH = 'content'
ARTICLE_PATHS = ['articles']
PAGE_PATHS = ['pages'] Any articles in If I changed it to: pelicanconf.py USE_FOLDER_AS_CATEGORY = True
PATH = 'content'
ARTICLE_PATHS = ['article_src_1', 'article_src_2']
PAGE_PATHS = ['page_src_1', 'page_src_2'] Then articles and pages in the two different folders (e.g. |
@bberberov Yes, that is the intended behavior.
One way of doing what you want would be utilizing PATH_METADATA = '.*/(?P<category>[^/]+)/[^/]+'
DEFAULT_CATEGORY = 'default'
USE_FOLDER_AS_CATEGORY = False
ARTICLE_PATHS = ['article_src_1', 'article_src_2'] then it should assign categories for articles immediately inside
EDIT:
That is what |
@avaris I see. The regex is correct, by the way. I'll just use |
Given the lack of activity regarding this topic, I think it's best to close this issue for now. If someone wants to implement a solution and discuss it further, please post a comment here and we can resume discussion about it. |
I’ve been playing with path metadata and regexp, trying to extract “core” metadata from filename and path. This is what I ended up with:
The goal is to match date, category, slug and lang information in file paths, such as:
… while making only two of these patterns mandatory: category and title (the other ones can then be defined in the file itself). So we could have:
The regex works (I tested it quite a bit). But there's a number of issues with how Pelican uses the data. It seems that once the regex is compiled, all the named groups that matched nothing en up with a value of
None
, and Pelican doesn’t know what to do with those in this context. Hence a bunch of errors or issues.Missing dates yield an error
After some testing this is because the
date
named group in the regex returns None. It doesn’t matter if the filetest.md
has inlinedate
metadata: it still creates an error and the file is skipped.Missing slug
Pelican does not try to generate a slug from the title matched in the regex, or from the title metadata in the file itself. Or if it does use the title metadata in the file to generate a slug, it gets overwriten with a None value, or something like that.
lang set as None
I was trying to output the articles as:
When the
lang
metadata wasn't set, and matched as None in path metadata, I ended up with output paths such as:category clashes with USE_FOLDER_AS_CATEGORY
With the above regex and a source file at
my-cat/my-slug/index.en.md
, the regex matches category='my-cat', slug='my-slug' alright. But the output is then:if USE_FOLDER_AS_CATEGORY is True.
The simple solution is to set USE_FOLDER_AS_CATEGORY to False. But maybe the USE_FOLDER_AS_CATEGORY behavior shouldn't overwrite the
category
metadata if it's already set/extracted?The text was updated successfully, but these errors were encountered: