diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 93c626c0..09840e8a 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -176,7 +176,9 @@ Note that, aside from the title, none of this metadata is mandatory: if the date is not specified, Pelican will rely on the file's "mtime" timestamp, and the category can be determined by the directory in which the file resides. For example, a file located at ``python/foobar/myfoobar.rst`` will have a category of -``foobar``. +``foobar``. If you would like to organize your files in other ways where the +name of the subfolder would not be a good category name, you can set the +setting ``USE_FOLDER_AS_CATEGORY`` to ``False``. Generate your blog ------------------ diff --git a/docs/settings.rst b/docs/settings.rst index af6bc8c0..1e3704d2 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -34,6 +34,10 @@ Setting name (default value) What doe `DATE_FORMATS` (``{}``) If you do manage multiple languages, you can set the date formatting here. See "Date format and locales" section below for details. +`USE_FOLDER_AS_CATEGORY` (``True``) When you don't specify a category in your post metadata and set this + setting to ``True`` and organize your articles in subfolders, the + subfolder will become the category of your post. If set to ``False`` + ``DEFAULT_CATEGORY`` will be used as a fallback. `DEFAULT_CATEGORY` (``'misc'``) The default category to fall back on. `DEFAULT_DATE_FORMAT` (``'%a %d %B %Y'``) The default date format you want to use. `DISPLAY_PAGES_ON_MENU` (``True``) Whether to display pages on the menu of the diff --git a/pelican/contents.py b/pelican/contents.py index 0dee19f3..74a66934 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -121,7 +121,8 @@ class Page(object): 'lang': getattr(self, 'lang', 'en'), 'date': getattr(self, 'date', datetime.now()), 'author': self.author, - 'category': getattr(self, 'category', 'misc'), + 'category': getattr(self, 'category', + self.settings['DEFAULT_CATEGORY']), } def _expand_settings(self, key): diff --git a/pelican/generators.py b/pelican/generators.py index fdec93fa..c38409a1 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -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) diff --git a/pelican/settings.py b/pelican/settings.py index 4d1ed81e..610d0733 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -34,6 +34,7 @@ _DEFAULT_CONFIG = {'PATH': '.', 'PDF_GENERATOR': False, 'OUTPUT_SOURCES': False, 'OUTPUT_SOURCES_EXTENSION': '.text', + 'USE_FOLDER_AS_CATEGORY': True, 'DEFAULT_CATEGORY': 'misc', 'DEFAULT_DATE': 'fs', 'WITH_FUTURE_DATES': True,