Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taxonomy improvements #2943

Merged
merged 2 commits into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions nikola/plugins/misc/taxonomies_classifier.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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