Skip to content

Commit

Permalink
Avoid creating broken links.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Jun 11, 2017
1 parent e17cb8c commit 15e9a9a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nikola/plugins/task/authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def provide_context_and_uptodate(self, classification, lang, node=None):

def get_other_language_variants(self, classification, lang, classifications_per_language):
"""Return a list of variants of the same author in other languages."""
return self.translation_manager.get_translations_as_list(classification, lang)
return self.translation_manager.get_translations_as_list(classification, lang, classifications_per_language)

def postprocess_posts_per_classification(self, posts_per_classification_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."""
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/task/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def provide_context_and_uptodate(self, classification, lang, node=None):

def get_other_language_variants(self, classification, lang, classifications_per_language):
"""Return a list of variants of the same category in other languages."""
return self.translation_manager.get_translations_as_list(classification, lang)
return self.translation_manager.get_translations_as_list(classification, lang, classifications_per_language)

def postprocess_posts_per_classification(self, posts_per_classification_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."""
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/task/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ def should_generate_classification_page(self, classification, post_list, lang):

def get_other_language_variants(self, classification, lang, classifications_per_language):
"""Return a list of variants of the same section in other languages."""
return self.translation_manager.get_translations_as_list(classification, lang)
return self.translation_manager.get_translations_as_list(classification, lang, classifications_per_language)
2 changes: 1 addition & 1 deletion nikola/plugins/task/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def provide_context_and_uptodate(self, classification, lang, node=None):

def get_other_language_variants(self, classification, lang, classifications_per_language):
"""Return a list of variants of the same tag in other languages."""
return self.translation_manager.get_translations_as_list(classification, lang)
return self.translation_manager.get_translations_as_list(classification, lang, classifications_per_language)

def postprocess_posts_per_classification(self, posts_per_classification_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."""
Expand Down
11 changes: 8 additions & 3 deletions nikola/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2002,16 +2002,21 @@ def get_translations(self, classification, lang):
else:
return {other_lang: list(classifications) for other_lang, classifications in cldata.items()}

def get_translations_as_list(self, classification, lang):
"""Get a list of pairs ``(other_lang, other_classification)`` which are translations of ``classification``."""
def get_translations_as_list(self, classification, lang, classifications_per_language):
"""Get a list of pairs ``(other_lang, other_classification)`` which are translations of ``classification``.
Avoid classifications not in ``classifications_per_language``.
"""
clmap = self._data[lang]
cldata = clmap.get(classification)
if cldata is None:
return []
else:
result = []
for other_lang, classifications in cldata.items():
result.extend([(other_lang, other_classification) for other_classification in classifications])
for other_classification in classifications:
if other_classification in classifications_per_language[other_lang]:
result.append((other_lang, other_classification))
return result

def has_translations(self, classification, lang):
Expand Down

0 comments on commit 15e9a9a

Please sign in to comment.