Skip to content
Permalink
Browse files
Support CATEGORY_DESTPATH_NAMES with pages following destpath
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 9, 2018
1 parent 26c8f2b commit 1eb1e12f99ec5fffaa588cf16f08479b899ef53b
Showing with 23 additions and 2 deletions.
  1. +1 −0 CHANGES.txt
  2. +1 −0 nikola/conf.py.in
  3. +8 −0 nikola/nikola.py
  4. +13 −2 nikola/plugins/task/categories.py
@@ -9,6 +9,7 @@ Features
Bugfixes
--------

* Support ``CATEGORY_DESTPATH_NAMES`` with pages following destpath
* Make ``CATEGORY_PAGES_FOLLOW_DESTPATH`` more resilient (Issue #3081)
* Guard against null items in gallery meta files (Issues #3076, #3077)
* Respect ``USE_FILENAME_AS_TITLE`` in galleries with a meta file
@@ -385,6 +385,7 @@ HIDDEN_CATEGORIES = []
# CATEGORY_DESTPATH_NAMES = {
# DEFAULT_LANG: {
# 'webdev': 'Web Development',
# 'webdev/django': 'Web Development/Django',
# 'random': 'Odds and Ends',
# },
# }
@@ -768,6 +768,14 @@ def __init__(self, **config):
utils.LOGGER.error('CATEGORY_PAGES_FOLLOW_DESTPATH requires CATEGORY_ALLOW_HIERARCHIES = True, CATEGORY_OUTPUT_FLAT_HIERARCHY = False.')
sys.exit(1)

# Needed to undo names for CATEGORY_PAGES_FOLLOW_DESTPATH
destpath_names_reverse = {}
for lang in self.config['TRANSLATIONS']:
destpath_names_reverse[lang] = {}
for k, v in self.config['CATEGORY_DESTPATH_NAMES'](lang).items():
destpath_names_reverse[lang][v] = k
self.config['_CATEGORY_DESTPATH_NAMES_REVERSE'] = utils.TranslatableSetting('_CATEGORY_DESTPATH_NAMES_REVERSE', destpath_names_reverse, self.config['TRANSLATIONS'])

# Handle CONTENT_FOOTER and RSS_COPYRIGHT* properly.
# We provide the arguments to format in CONTENT_FOOTER_FORMATS and RSS_COPYRIGHT_FORMATS.
self.config['CONTENT_FOOTER'].langformat(self.config['CONTENT_FOOTER_FORMATS'])
@@ -125,17 +125,28 @@ def slugify_category_name(self, path, lang):
def get_path(self, classification, lang, dest_type='page'):
"""Return a path for the given classification."""
cat_string = '/'.join(classification)
classification_raw = classification # needed to undo CATEGORY_DESTPATH_NAMES
cat_names_reverse = self.site.config['_CATEGORY_DESTPATH_NAMES_REVERSE'](lang)
if self.site.config['CATEGORY_PAGES_FOLLOW_DESTPATH']:
base_dir = None
for post in self.site.posts_per_category[cat_string]:
if post.category_from_destpath:
base_dir = post.folder_base(lang)
# Handle CATEGORY_DESTPATH_NAMES
if cat_string in cat_names_reverse:
cat_string = cat_names_reverse[cat_string]
classification_raw = cat_string.split('/')
break
# fallback: first POSTS entry + classification

if not self.site.config['CATEGORY_DESTPATH_TRIM_PREFIX']:
# If prefixes are not trimmed, we'll already have the base_dir in classification_raw
base_dir = ''

if base_dir is None:
# fallback: first POSTS entry + classification
base_dir = self.site.config['POSTS'][0][1]
base_dir_list = base_dir.split(os.sep)
sub_dir = [self.slugify_tag_name(part, lang) for part in classification]
sub_dir = [self.slugify_tag_name(part, lang) for part in classification_raw]
return [_f for _f in (base_dir_list + sub_dir) if _f], 'auto'
else:
return [_f for _f in [self.site.config['CATEGORY_PATH'](lang)] if _f] + self.slugify_category_name(

0 comments on commit 1eb1e12

Please sign in to comment.