Skip to content

Commit

Permalink
Merge pull request #2943 from getnikola/taxonomy-improvements
Browse files Browse the repository at this point in the history
Taxonomy improvements
  • Loading branch information
Kwpolska committed Jan 7, 2018
2 parents 68ced32 + e643812 commit f37b51f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
54 changes: 28 additions & 26 deletions nikola/plugins/misc/taxonomies_classifier.py
Expand Up @@ -160,34 +160,36 @@ def create_hierarchy(hierarchy, parent=None, level=0):
for lang in site.config['TRANSLATIONS'].keys():
if not taxonomy.is_enabled(lang):
continue
for tlang in site.config['TRANSLATIONS'].keys():
if lang != tlang:
for classification, posts in site.posts_per_classification[taxonomy.classification_name][lang].items():
# Do we actually generate this classification page?
filtered_posts = [x for x in posts if self.site.config["SHOW_UNTRANSLATED_POSTS"] or x.is_translation_available(lang)]
generate_list = taxonomy.should_generate_classification_page(classification, filtered_posts, lang)
if not generate_list:
continue
for classification, posts in site.posts_per_classification[taxonomy.classification_name][tlang].items():
# Obtain path as tuple
path = site.path_handlers[taxonomy.classification_name](classification, lang)
# Check that path is OK
for path_element in path:
if len(path_element) == 0:
utils.LOGGER.error("{0} {1} yields invalid path '{2}'!".format(taxonomy.classification_name.title(), classification, '/'.join(path)))
quit = True
# Combine path
path = os.path.join(*[os.path.normpath(p) for p in path if p != '.'])
# Determine collisions
if path in taxonomy_outputs[lang]:
other_classification_name, other_classification, other_posts = taxonomy_outputs[lang][path]
if other_classification_name == taxonomy.classification_name and other_classification == classification:
taxonomy_outputs[lang][path][2].extend(posts)
else:
utils.LOGGER.error('You have classifications that are too similar: {0} "{1}" and {2} "{3}" both result in output path {4} for language {5}.'.format(
taxonomy.classification_name, classification, other_classification_name, other_classification, path, lang))
utils.LOGGER.error('{0} {1} is used in: {2}'.format(
taxonomy.classification_name.title(), classification, ', '.join(sorted([p.source_path for p in posts]))))
utils.LOGGER.error('{0} {1} is used in: {2}'.format(
other_classification_name.title(), other_classification, ', '.join(sorted([p.source_path for p in other_posts]))))
quit = True
# Obtain path as tuple
path = site.path_handlers[taxonomy.classification_name](classification, lang)
# Check that path is OK
for path_element in path:
if len(path_element) == 0:
utils.LOGGER.error("{0} {1} yields invalid path '{2}'!".format(taxonomy.classification_name.title(), classification, '/'.join(path)))
quit = True
# Combine path
path = os.path.join(*[os.path.normpath(p) for p in path if p != '.'])
# Determine collisions
if path in taxonomy_outputs[lang]:
other_classification_name, other_classification, other_posts = taxonomy_outputs[lang][path]
if other_classification_name == taxonomy.classification_name and other_classification == classification:
taxonomy_outputs[lang][path][2].extend(filtered_posts)
else:
taxonomy_outputs[lang][path] = (taxonomy.classification_name, classification, list(posts))
utils.LOGGER.error('You have classifications that are too similar: {0} "{1}" and {2} "{3}" both result in output path {4} for language {5}.'.format(
taxonomy.classification_name, classification, other_classification_name, other_classification, path, lang))
utils.LOGGER.error('{0} "{1}" is used in: {2}'.format(
taxonomy.classification_name.title(), classification, ', '.join(sorted([p.source_path for p in filtered_posts]))))
utils.LOGGER.error('{0} "{1}" is used in: {2}'.format(
other_classification_name.title(), other_classification, ', '.join(sorted([p.source_path for p in other_posts]))))
quit = True
else:
taxonomy_outputs[lang][path] = (taxonomy.classification_name, classification, list(posts))
if quit:
sys.exit(1)
blinker.signal('taxonomies_classified').send(site)
Expand Down
7 changes: 1 addition & 6 deletions nikola/plugins/task/taxonomies.py
Expand Up @@ -423,13 +423,8 @@ def gen_tasks(self):
for taxonomy in self.site.taxonomy_plugins.values():
plpl = {}
for lang in self.site.config["TRANSLATIONS"]:
classifications = {}
for tlang, posts_per_classification in self.site.posts_per_classification[taxonomy.classification_name].items():
if lang != tlang:
continue
classifications.update(posts_per_classification)
result = {}
for classification, posts in classifications.items():
for classification, posts in self.site.posts_per_classification[taxonomy.classification_name][lang].items():
# Filter list
filtered_posts = self._filter_list(posts, lang)
if len(filtered_posts) == 0 and taxonomy.omit_empty_classifications:
Expand Down

0 comments on commit f37b51f

Please sign in to comment.