Skip to content

Commit

Permalink
Adding post count (and children count) to new variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Dec 1, 2016
1 parent f55b584 commit d8fce5c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
9 changes: 7 additions & 2 deletions nikola/plugin_categories.py
Expand Up @@ -554,8 +554,13 @@ class Taxonomy(BasePlugin):
Set to None to avoid generating overviews.
add_postcount_in_overview = False:
If set to True, the lists provided to the template when rendering the
overview also contain the post count as a last element per item.
If set to True, two more variables `'items_with_postcount'` and
`overview_page_hierarchy_variable_name + '_with_postcount'` (for
hierarchical taxonomies) besides the `'items'` and
`overview_page_hierarchy_variable_name` will be available in the
overview page's template. These new variables will contain the post
count for every classification, and in case of the hierarchy, also
the number of children for every node.
always_disable_rss = False:
Whether to always disable RSS feed generation
Expand Down
40 changes: 21 additions & 19 deletions nikola/plugins/task/taxonomies.py
Expand Up @@ -104,20 +104,30 @@ def acceptor(node):

# Set up classifications in context
context[taxonomy.overview_page_variable_name] = classifications
if taxonomy.add_postcount_in_overview:
items = [(classification,
self.site.link(taxonomy.classification_name, classification, lang),
len(self._filter_list(self.site.posts_per_classification[taxonomy.classification_name][lang][classification], lang)))
for classification in classifications]
else:
items = [(classification,
self.site.link(taxonomy.classification_name, classification, lang))
for classification in classifications]
items = [(classification,
self.site.link(taxonomy.classification_name, classification, lang))
for classification in classifications]
context["items"] = items
if taxonomy.add_postcount_in_overview:
items_with_postcount = [
(classification,
self.site.link(taxonomy.classification_name, classification, lang),
len(self._filter_list(self.site.posts_per_classification[taxonomy.classification_name][lang][classification], lang)))
for classification in classifications
]
context["items_with_postcount"] = items_with_postcount
context["has_hierarchy"] = taxonomy.has_hierarchy
if taxonomy.has_hierarchy and taxonomy.overview_page_hierarchy_variable_name:
hier_items = [
(node.name, node.classification_name, node.classification_path,
self.site.link(taxonomy.classification_name, node.classification_name, lang),
node.indent_levels, node.indent_change_before,
node.indent_change_after)
for node in clipped_flat_hierarchy
]
context[taxonomy.overview_page_hierarchy_variable_name] = hier_items
if taxonomy.add_postcount_in_overview:
hier_items = [
hier_items_with_postcount = [
(node.name, node.classification_name, node.classification_path,
self.site.link(taxonomy.classification_name, node.classification_name, lang),
node.indent_levels, node.indent_change_before,
Expand All @@ -126,15 +136,7 @@ def acceptor(node):
len(self._filter_list(self.site.posts_per_classification[taxonomy.classification_name][lang][node.classification_name], lang)))
for node in clipped_flat_hierarchy
]
else:
hier_items = [
(node.name, node.classification_name, node.classification_path,
self.site.link(taxonomy.classification_name, node.classification_name, lang),
node.indent_levels, node.indent_change_before,
node.indent_change_after)
for node in clipped_flat_hierarchy
]
context[taxonomy.overview_page_hierarchy_variable_name] = hier_items
context[taxonomy.overview_page_hierarchy_variable_name + '_with_postcount'] = hier_items_with_postcount

# Prepare rendering
context["permalink"] = self.site.link("{}_index".format(taxonomy.classification_name), None, lang)
Expand Down

0 comments on commit d8fce5c

Please sign in to comment.