Skip to content
Permalink
Browse files
Fix #1856 -- make tag listing pages per-language
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 4, 2015
1 parent e8ce9bb commit ca6a18a479ffceb074e57ceb2540d4f9802a7ea9
Showing with 18 additions and 9 deletions.
  1. +6 −0 nikola/nikola.py
  2. +6 −6 nikola/plugins/task/tags.py
  3. +6 −3 nikola/post.py
@@ -273,6 +273,7 @@ def __init__(self, **config):
self.posts_per_month = defaultdict(list)
self.posts_per_tag = defaultdict(list)
self.posts_per_category = defaultdict(list)
self.tags_per_language = defaultdict(list)
self.post_per_file = {}
self.timeline = []
self.pages = []
@@ -1440,6 +1441,7 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):
self.posts_per_month = defaultdict(list)
self.posts_per_tag = defaultdict(list)
self.posts_per_category = defaultdict(list)
self.tags_per_language = defaultdict(list)
self.category_hierarchy = {}
self.post_per_file = {}
self.timeline = []
@@ -1472,6 +1474,8 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):
else:
slugged_tags.add(utils.slugify(tag, force=True))
self.posts_per_tag[tag].append(post)
for lang in post.translated_to:
self.tags_per_language[lang].extend(post.tags_for_language(lang))
self._add_post_to_category(post, post.meta('category'))

if post.is_post:
@@ -1497,6 +1501,8 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):
quit = True
self.post_per_file[dest] = post
self.post_per_file[src_dest] = post
# deduplicate tags_per_language
self.tags_per_language[lang] = list(set(self.tags_per_language[lang]))

# Sort everything.

@@ -179,19 +179,19 @@ def write_tag_data(data):

def _create_tags_page(self, kw, include_tags=True, include_categories=True):
"""a global "all your tags/categories" page for each language"""
tags = natsort.natsorted([tag for tag in self.site.posts_per_tag.keys()
if len(self.site.posts_per_tag[tag]) >= kw["taglist_minimum_post_count"]],
alg=natsort.ns.F | natsort.ns.IC)
categories = [cat.category_name for cat in self.site.category_hierarchy]
has_tags = (tags != []) and include_tags
has_categories = (categories != []) and include_categories
template_name = "tags.tmpl"
kw = kw.copy()
if include_tags:
kw['tags'] = tags
if include_categories:
kw['categories'] = categories
for lang in kw["translations"]:
tags = natsort.natsorted([tag for tag in self.site.tags_per_language[lang]
if len(self.site.posts_per_tag[tag]) >= kw["taglist_minimum_post_count"]],
alg=natsort.ns.F | natsort.ns.IC)
has_tags = (tags != []) and include_tags
if include_tags:
kw['tags'] = tags
output_name = os.path.join(
kw['output_folder'], self.site.path('tag_index' if has_tags else 'category_index', None, lang))
output_name = output_name
@@ -261,16 +261,19 @@ def alltags(self):
tags.extend(self._tags[l])
return list(set(tags))

@property
def tags(self):
lang = nikola.utils.LocaleBorg().current_lang
def tags_for_language(self, lang):
if lang in self._tags:
return self._tags[lang]
elif self.default_lang in self._tags:
return self._tags[self.default_lang]
else:
return []

@property
def tags(self):
lang = nikola.utils.LocaleBorg().current_lang
return self.tags_for_language(lang)

@property
def prev_post(self):
lang = nikola.utils.LocaleBorg().current_lang

0 comments on commit ca6a18a

Please sign in to comment.