Skip to content
Permalink
Browse files

Avoid empty subarchive pages. Fix archive navigation.

  • Loading branch information
felixfontein committed Apr 24, 2017
1 parent 75ba0bc commit 3a811b854dd5a64bc20ea5f0e0dd4834376b5086
Showing with 6 additions and 3 deletions.
  1. +6 −3 nikola/plugins/task/archive.py
@@ -219,7 +219,7 @@ def provide_context_and_uptodate(self, classification, lang, node=None):
kw.update(context)
return context, kw

def postprocess_posts_per_classification(self, posts_per_section_per_language, flat_hierarchy_per_lang=None, hierarchy_lookup_per_lang=None):
def postprocess_posts_per_classification(self, posts_per_archive_per_language, flat_hierarchy_per_lang=None, hierarchy_lookup_per_lang=None):
"""Rearrange, modify or otherwise use the list of posts per classification and per language."""
# Build a lookup table for archive navigation, if we’ll need one.
if self.site.config['CREATE_ARCHIVE_NAVIGATION']:
@@ -229,14 +229,17 @@ def postprocess_posts_per_classification(self, posts_per_section_per_language, f
for lang, flat_hierarchy in flat_hierarchy_per_lang.items():
self.archive_navigation[lang] = defaultdict(list)
for node in flat_hierarchy:
if not self.site.config["SHOW_UNTRANSLATED_POSTS"]:
if not [x for x in posts_per_archive_per_language[lang][node.classification_name] if x.is_translation_available(lang)]:
continue
self.archive_navigation[lang][len(node.classification_path)].append(node.classification_name)

# We need to sort it. Natsort means it’s year 10000 compatible!
for k, v in self.archive_navigation[lang].items():
self.archive_navigation[lang][k] = natsort.natsorted(v, alg=natsort.ns.F | natsort.ns.IC)

return super(Archive, self).postprocess_posts_per_classification(posts_per_section_per_language, flat_hierarchy_per_lang, hierarchy_lookup_per_lang)
return super(Archive, self).postprocess_posts_per_classification(posts_per_archive_per_language, flat_hierarchy_per_lang, hierarchy_lookup_per_lang)

def should_generate_classification_page(self, classification, post_list, lang):
"""Only generates list of posts for classification if this function returns True."""
return len(classification.split('/')) < 3 or len(post_list) > 0
return classification = '' or len(post_list) > 0

0 comments on commit 3a811b8

Please sign in to comment.
You can’t perform that action at this time.