mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Added USE_FOLDER_AS_CATEGORY setting.
This allows users to organize their files in ways where the subfolder name would not make a good category name (i.e. /2012/09/). Set this to ``False`` and the subfolder will no longer be used as a standard category, `DEFAULT_CATEGORY` will be used instead.
This commit is contained in:
parent
a282499055
commit
47c972e21a
5 changed files with 17 additions and 6 deletions
|
|
@ -280,11 +280,14 @@ class ArticlesGenerator(Generator):
|
|||
# if no category is set, use the name of the path as a category
|
||||
if 'category' not in metadata:
|
||||
|
||||
if os.path.dirname(f) == article_path: # if the article is not in a subdirectory
|
||||
category = self.settings['DEFAULT_CATEGORY']
|
||||
else:
|
||||
if (self.settings['USE_FOLDER_AS_CATEGORY']
|
||||
and os.path.dirname(f) != article_path):
|
||||
# if the article is in a subdirectory
|
||||
category = os.path.basename(os.path.dirname(f))\
|
||||
.decode('utf-8')
|
||||
.decode('utf-8')
|
||||
else:
|
||||
# if the article is not in a subdirectory
|
||||
category = self.settings['DEFAULT_CATEGORY']
|
||||
|
||||
if category != '':
|
||||
metadata['category'] = Category(category, self.settings)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue