Skip to content
Permalink
Browse files

Adding post count (and children count) to new variables.

  • Loading branch information
felixfontein committed Dec 1, 2016
1 parent f55b584 commit d8fce5c7a87b4a69c3b0bdb5f5508526cc32cf7b
Showing with 28 additions and 21 deletions.
  1. +7 −2 nikola/plugin_categories.py
  2. +21 −19 nikola/plugins/task/taxonomies.py
@@ -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
@@ -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,
@@ -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)

0 comments on commit d8fce5c

Please sign in to comment.
You can’t perform that action at this time.