Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Compute reverse destpath dict in categories.py
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 10, 2018
1 parent 2ca685c commit 41232c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 0 additions & 8 deletions nikola/nikola.py
Expand Up @@ -768,14 +768,6 @@ 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'])
Expand Down
16 changes: 13 additions & 3 deletions nikola/plugins/task/categories.py
Expand Up @@ -84,6 +84,16 @@ def set_site(self, site):
self.template_for_single_list = "tagindex.tmpl" if self.show_list_as_index else "tag.tmpl"
self.translation_manager = utils.ClassificationTranslationManager()

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

def is_enabled(self, lang=None):
"""Return True if this taxonomy is enabled, or False otherwise."""
return True
Expand Down Expand Up @@ -126,15 +136,15 @@ 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)
destpath_names_reverse = self.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]
if cat_string in destpath_names_reverse:
cat_string = destpath_names_reverse[cat_string]
classification_raw = cat_string.split('/')
break

Expand Down

0 comments on commit 41232c1

Please sign in to comment.