We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
CATEGORY_ALLOW_HIERARCHIES does not work


### Environment (if reporting a bug)

**Python Version:**
3.5.2

**Nikola Version:**
7.8.3 and master

**Operating System:**
Ubuntu 16.04

### Description:

I installed nikola in virtualenv from pip.
Then I set CATEGORY_ALLOW_HIERARCHIES to True in conf.py.
I created new post and edit category to be ".. category: code/python"
The error when building site:
```
TaskError - taskid:render_taxonomies:output/categories/cat_code/index.html
PythonAction Error
Traceback (most recent call last):
  File "/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/doit/action.py", line 403, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/nikola/nikola.py", line 1396, in render_template
    template_name, None, local_context)
  File "/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/nikola/plugins/template/mako.py", line 117, in render_template
    data = template.render_unicode(**context)
  File "/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/mako/template.py", line 471, in render_unicode
    as_unicode=True)
  File "/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/mako/runtime.py", line 838, in _render
    **_kwargs_for_callable(callable_, data))
  File "/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/mako/runtime.py", line 873, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/mako/runtime.py", line 899, in _exec_template
    callable_(context, *args, **kwargs)
  File "/home/denin/Workspace/nikola/nikola3/my_first_site/cache/.mako.tmp/base.tmpl.py", line 127, in render_body
    context['self'].content(**pageargs)
  File "/home/denin/Workspace/nikola/nikola3/my_first_site/cache/.mako.tmp/tag.tmpl.py", line 137, in render_content
    for name, link in subcategories:
ValueError: too many values to unpack (expected 2)
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nikola/plugins/task/categories.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 # Copyright © 2012-2017 Roberto Alsina and others.
4 
5 # Permission is hereby granted, free of charge, to any
6 # person obtaining a copy of this software and associated
7 # documentation files (the "Software"), to deal in the
8 # Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the
11 # Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice
15 # shall be included in all copies or substantial portions of
16 # the Software.
17 #
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
22 # OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 
27 """Render the category pages and feeds."""
28 
29 from __future__ import unicode_literals
30 
31 from nikola.plugin_categories import Taxonomy
32 from nikola import utils
33 
34 
35 class ClassifyCategories(Taxonomy):
36     """Classify the posts by categories."""
37 
38     name = "classify_categories"
39 
40     classification_name = "category"
41     overview_page_variable_name = "categories"
42     overview_page_items_variable_name = "cat_items"
43     overview_page_hierarchy_variable_name = "cat_hierarchy"
44     more_than_one_classifications_per_post = False
45     has_hierarchy = True
46     include_posts_from_subhierarchies = True
47     include_posts_into_hierarchy_root = False
48     show_list_as_subcategories_list = False
49     generate_atom_feeds_for_post_lists = True
50     template_for_classification_overview = "tags.tmpl"
51     always_disable_rss = False
52     apply_to_posts = True
53     apply_to_pages = False
54     minimum_post_count_per_classification_in_overview = 1
55     omit_empty_classifications = True
56     also_create_classifications_from_other_languages = True
57     path_handler_docstrings = {
58         'category_index': """A link to the category index.
59 
60 Example:
61 
62 link://category_index => /categories/index.html""",
63         'category': """A link to a category. Takes page number as optional keyword argument.
64 
65 Example:
66 
67 link://category/dogs => /categories/dogs.html""",
68         'category_atom': """A link to a category's Atom feed.
69 
70 Example:
71 
72 link://category_atom/dogs => /categories/dogs.atom""",
73         'category_rss': """A link to a category's RSS feed.
74 
75 Example:
76 
77 link://category_rss/dogs => /categories/dogs.xml""",
78     }
79 
80     def set_site(self, site):
81         """Set site, which is a Nikola instance."""
82         super(ClassifyCategories, self).set_site(site)
83         self.show_list_as_index = self.site.config['CATEGORY_PAGES_ARE_INDEXES']
84         self.template_for_single_list = "tagindex.tmpl" if self.show_list_as_index else "tag.tmpl"
85 
86     def is_enabled(self, lang=None):
87         """Return True if this taxonomy is enabled, or False otherwise."""
88         return True
89 
90     def classify(self, post, lang):
91         """Classify the given post for the given language."""
92         cat = post.meta('category', lang=lang).strip()
93         return [cat] if cat else []
94 
95     def get_classification_friendly_name(self, classification, lang, only_last_component=False):
96         """Extract a friendly name from the classification."""
97         classification = self.extract_hierarchy(classification)
98         return classification[-1] if classification else ''
99 
100     def get_overview_path(self, lang, dest_type='page'):
101         """A path handler for the list of all classifications."""
102         if self.site.config['CATEGORIES_INDEX_PATH'](lang):
103             path = self.site.config['CATEGORIES_INDEX_PATH'](lang)
104             if path.endswith('/index'):  # TODO: remove in v8
105                 utils.LOGGER.warn("CATEGORIES_INDEX_PATH for language {0} is missing a .html extension. Please update your configuration!".format(lang))
106                 path += '.html'
107             return [_f for _f in [path] if _f], 'never'
108         else:
109             return [_f for _f in [self.site.config['CATEGORY_PATH'](lang)] if _f], 'always'
110 
111     def slugify_tag_name(self, name, lang):
112         """Slugify a tag name."""
113         if self.site.config['SLUG_TAG_PATH']:
114             name = utils.slugify(name, lang)
115         return name
116 
117     def slugify_category_name(self, path, lang):
118         """Slugify a category name."""
119         if lang is None:  # TODO: remove in v8
120             utils.LOGGER.warn("ClassifyCategories.slugify_category_name() called without language!")
121             lang = ''
122         if self.site.config['CATEGORY_OUTPUT_FLAT_HIERARCHY']:
123             path = path[-1:]  # only the leaf
124         result = [self.slugify_tag_name(part, lang) for part in path]
125         result[0] = self.site.config['CATEGORY_PREFIX'] + result[0]
126         if not self.site.config['PRETTY_URLS']:
127             result = ['-'.join(result)]
128         return result
129 
130     def get_path(self, classification, lang, dest_type='page'):
131         """A path handler for the given classification."""
132         return [_f for _f in [self.site.config['CATEGORY_PATH'](lang)] if _f] + self.slugify_category_name(classification, lang), 'auto'
133 
134     def extract_hierarchy(self, classification):
135         """Given a classification, return a list of parts in the hierarchy."""
136         return utils.parse_escaped_hierarchical_category_name(classification)
137 
138     def recombine_classification_from_hierarchy(self, hierarchy):
139         """Given a list of parts in the hierarchy, return the classification string."""
140         return utils.join_hierarchical_category_path(hierarchy)
141 
142     def provide_overview_context_and_uptodate(self, lang):
143         """Provide data for the context and the uptodate list for the list of all classifiations."""
144         kw = {
145             'category_path': self.site.config['CATEGORY_PATH'],
146             'category_prefix': self.site.config['CATEGORY_PREFIX'],
147             "category_pages_are_indexes": self.site.config['CATEGORY_PAGES_ARE_INDEXES'],
148             "tzinfo": self.site.tzinfo,
149             "category_pages_descriptions": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'],
150             "category_pages_titles": self.site.config['CATEGORY_PAGES_TITLES'],
151         }
152         context = {
153             "title": self.site.MESSAGES[lang]["Categories"],
154             "description": self.site.MESSAGES[lang]["Categories"],
155             "pagekind": ["list", "tags_page"],
156         }
157         kw.update(context)
158         return context, kw
159 
160     def provide_context_and_uptodate(self, cat, lang, node=None):
161         """Provide data for the context and the uptodate list for the list of the given classifiation."""
162         cat_path = self.extract_hierarchy(cat)
163         kw = {
164             'category_path': self.site.config['CATEGORY_PATH'],
165             'category_prefix': self.site.config['CATEGORY_PREFIX'],
166             "category_pages_are_indexes": self.site.config['CATEGORY_PAGES_ARE_INDEXES'],
167             "tzinfo": self.site.tzinfo,
168             "category_pages_descriptions": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'],
169             "category_pages_titles": self.site.config['CATEGORY_PAGES_TITLES'],
170         }
171         posts = self.site.posts_per_classification[self.classification_name][lang]
172         children = [child for child in node.children if len([post for post in posts.get(child.classification_name, []) if self.site.config['SHOW_UNTRANSLATED_POSTS'] or post.is_translation_available(lang)]) > 0]
173         subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang), child.classification_name, child.classification_path) for child in children]
174         friendly_name = self.get_classification_friendly_name(cat, lang)
175         context = {
176             "title": self.site.config['CATEGORY_PAGES_TITLES'].get(lang, {}).get(cat, self.site.MESSAGES[lang]["Posts about %s"] % friendly_name),
177             "description": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'].get(lang, {}).get(cat),
178             "kind": "category",
179             "pagekind": ["tag_page", "index" if self.show_list_as_index else "list"],
180             "tag": friendly_name,
181             "category": cat,
182             "category_path": cat_path,
183             "subcategories": subcats,
184         }
185         if self.show_list_as_index:
186             context["rss_link"] = """<link rel="alternate" type="application/rss+xml" type="application/rss+xml" title="RSS for tag {0} ({1})" href="{2}">""".format(friendly_name, lang, self.site.link("category_rss", cat, lang))
187         kw.update(context)
188         return context, kw
189
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/nikola/plugins/task/categories.py b/nikola/plugins/task/categories.py
--- a/nikola/plugins/task/categories.py
+++ b/nikola/plugins/task/categories.py
@@ -170,7 +170,7 @@
         }
         posts = self.site.posts_per_classification[self.classification_name][lang]
         children = [child for child in node.children if len([post for post in posts.get(child.classification_name, []) if self.site.config['SHOW_UNTRANSLATED_POSTS'] or post.is_translation_available(lang)]) > 0]
-        subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang), child.classification_name, child.classification_path) for child in children]
+        subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang)) for child in children]
         friendly_name = self.get_classification_friendly_name(cat, lang)
         context = {
             "title": self.site.config['CATEGORY_PAGES_TITLES'].get(lang, {}).get(cat, self.site.MESSAGES[lang]["Posts about %s"] % friendly_name),

{"golden_diff": "diff --git a/nikola/plugins/task/categories.py b/nikola/plugins/task/categories.py\n--- a/nikola/plugins/task/categories.py\n+++ b/nikola/plugins/task/categories.py\n@@ -170,7 +170,7 @@\n         }\n         posts = self.site.posts_per_classification[self.classification_name][lang]\n         children = [child for child in node.children if len([post for post in posts.get(child.classification_name, []) if self.site.config['SHOW_UNTRANSLATED_POSTS'] or post.is_translation_available(lang)]) > 0]\n-        subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang), child.classification_name, child.classification_path) for child in children]\n+        subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang)) for child in children]\n         friendly_name = self.get_classification_friendly_name(cat, lang)\n         context = {\n             \"title\": self.site.config['CATEGORY_PAGES_TITLES'].get(lang, {}).get(cat, self.site.MESSAGES[lang][\"Posts about %s\"] % friendly_name),\n", "issue": "CATEGORY_ALLOW_HIERARCHIES does not work\n\r\n\r\n### Environment (if reporting a bug)\r\n\r\n**Python Version:**\r\n3.5.2\r\n\r\n**Nikola Version:**\r\n7.8.3 and master\r\n\r\n**Operating System:**\r\nUbuntu 16.04\r\n\r\n### Description:\r\n\r\nI installed nikola in virtualenv from pip.\r\nThen I set CATEGORY_ALLOW_HIERARCHIES to True in conf.py.\r\nI created new post and edit category to be \".. category: code/python\"\r\nThe error when building site:\r\n```\r\nTaskError - taskid:render_taxonomies:output/categories/cat_code/index.html\r\nPythonAction Error\r\nTraceback (most recent call last):\r\n  File \"/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/doit/action.py\", line 403, in execute\r\n    returned_value = self.py_callable(*self.args, **kwargs)\r\n  File \"/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/nikola/nikola.py\", line 1396, in render_template\r\n    template_name, None, local_context)\r\n  File \"/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/nikola/plugins/template/mako.py\", line 117, in render_template\r\n    data = template.render_unicode(**context)\r\n  File \"/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/mako/template.py\", line 471, in render_unicode\r\n    as_unicode=True)\r\n  File \"/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/mako/runtime.py\", line 838, in _render\r\n    **_kwargs_for_callable(callable_, data))\r\n  File \"/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/mako/runtime.py\", line 873, in _render_context\r\n    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)\r\n  File \"/home/denin/Workspace/nikola/nikola3/lib/python3.5/site-packages/mako/runtime.py\", line 899, in _exec_template\r\n    callable_(context, *args, **kwargs)\r\n  File \"/home/denin/Workspace/nikola/nikola3/my_first_site/cache/.mako.tmp/base.tmpl.py\", line 127, in render_body\r\n    context['self'].content(**pageargs)\r\n  File \"/home/denin/Workspace/nikola/nikola3/my_first_site/cache/.mako.tmp/tag.tmpl.py\", line 137, in render_content\r\n    for name, link in subcategories:\r\nValueError: too many values to unpack (expected 2)\r\n```\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright \u00a9 2012-2017 Roberto Alsina and others.\n\n# Permission is hereby granted, free of charge, to any\n# person obtaining a copy of this software and associated\n# documentation files (the \"Software\"), to deal in the\n# Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the\n# Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice\n# shall be included in all copies or substantial portions of\n# the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\n# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\"\"\"Render the category pages and feeds.\"\"\"\n\nfrom __future__ import unicode_literals\n\nfrom nikola.plugin_categories import Taxonomy\nfrom nikola import utils\n\n\nclass ClassifyCategories(Taxonomy):\n    \"\"\"Classify the posts by categories.\"\"\"\n\n    name = \"classify_categories\"\n\n    classification_name = \"category\"\n    overview_page_variable_name = \"categories\"\n    overview_page_items_variable_name = \"cat_items\"\n    overview_page_hierarchy_variable_name = \"cat_hierarchy\"\n    more_than_one_classifications_per_post = False\n    has_hierarchy = True\n    include_posts_from_subhierarchies = True\n    include_posts_into_hierarchy_root = False\n    show_list_as_subcategories_list = False\n    generate_atom_feeds_for_post_lists = True\n    template_for_classification_overview = \"tags.tmpl\"\n    always_disable_rss = False\n    apply_to_posts = True\n    apply_to_pages = False\n    minimum_post_count_per_classification_in_overview = 1\n    omit_empty_classifications = True\n    also_create_classifications_from_other_languages = True\n    path_handler_docstrings = {\n        'category_index': \"\"\"A link to the category index.\n\nExample:\n\nlink://category_index => /categories/index.html\"\"\",\n        'category': \"\"\"A link to a category. Takes page number as optional keyword argument.\n\nExample:\n\nlink://category/dogs => /categories/dogs.html\"\"\",\n        'category_atom': \"\"\"A link to a category's Atom feed.\n\nExample:\n\nlink://category_atom/dogs => /categories/dogs.atom\"\"\",\n        'category_rss': \"\"\"A link to a category's RSS feed.\n\nExample:\n\nlink://category_rss/dogs => /categories/dogs.xml\"\"\",\n    }\n\n    def set_site(self, site):\n        \"\"\"Set site, which is a Nikola instance.\"\"\"\n        super(ClassifyCategories, self).set_site(site)\n        self.show_list_as_index = self.site.config['CATEGORY_PAGES_ARE_INDEXES']\n        self.template_for_single_list = \"tagindex.tmpl\" if self.show_list_as_index else \"tag.tmpl\"\n\n    def is_enabled(self, lang=None):\n        \"\"\"Return True if this taxonomy is enabled, or False otherwise.\"\"\"\n        return True\n\n    def classify(self, post, lang):\n        \"\"\"Classify the given post for the given language.\"\"\"\n        cat = post.meta('category', lang=lang).strip()\n        return [cat] if cat else []\n\n    def get_classification_friendly_name(self, classification, lang, only_last_component=False):\n        \"\"\"Extract a friendly name from the classification.\"\"\"\n        classification = self.extract_hierarchy(classification)\n        return classification[-1] if classification else ''\n\n    def get_overview_path(self, lang, dest_type='page'):\n        \"\"\"A path handler for the list of all classifications.\"\"\"\n        if self.site.config['CATEGORIES_INDEX_PATH'](lang):\n            path = self.site.config['CATEGORIES_INDEX_PATH'](lang)\n            if path.endswith('/index'):  # TODO: remove in v8\n                utils.LOGGER.warn(\"CATEGORIES_INDEX_PATH for language {0} is missing a .html extension. Please update your configuration!\".format(lang))\n                path += '.html'\n            return [_f for _f in [path] if _f], 'never'\n        else:\n            return [_f for _f in [self.site.config['CATEGORY_PATH'](lang)] if _f], 'always'\n\n    def slugify_tag_name(self, name, lang):\n        \"\"\"Slugify a tag name.\"\"\"\n        if self.site.config['SLUG_TAG_PATH']:\n            name = utils.slugify(name, lang)\n        return name\n\n    def slugify_category_name(self, path, lang):\n        \"\"\"Slugify a category name.\"\"\"\n        if lang is None:  # TODO: remove in v8\n            utils.LOGGER.warn(\"ClassifyCategories.slugify_category_name() called without language!\")\n            lang = ''\n        if self.site.config['CATEGORY_OUTPUT_FLAT_HIERARCHY']:\n            path = path[-1:]  # only the leaf\n        result = [self.slugify_tag_name(part, lang) for part in path]\n        result[0] = self.site.config['CATEGORY_PREFIX'] + result[0]\n        if not self.site.config['PRETTY_URLS']:\n            result = ['-'.join(result)]\n        return result\n\n    def get_path(self, classification, lang, dest_type='page'):\n        \"\"\"A path handler for the given classification.\"\"\"\n        return [_f for _f in [self.site.config['CATEGORY_PATH'](lang)] if _f] + self.slugify_category_name(classification, lang), 'auto'\n\n    def extract_hierarchy(self, classification):\n        \"\"\"Given a classification, return a list of parts in the hierarchy.\"\"\"\n        return utils.parse_escaped_hierarchical_category_name(classification)\n\n    def recombine_classification_from_hierarchy(self, hierarchy):\n        \"\"\"Given a list of parts in the hierarchy, return the classification string.\"\"\"\n        return utils.join_hierarchical_category_path(hierarchy)\n\n    def provide_overview_context_and_uptodate(self, lang):\n        \"\"\"Provide data for the context and the uptodate list for the list of all classifiations.\"\"\"\n        kw = {\n            'category_path': self.site.config['CATEGORY_PATH'],\n            'category_prefix': self.site.config['CATEGORY_PREFIX'],\n            \"category_pages_are_indexes\": self.site.config['CATEGORY_PAGES_ARE_INDEXES'],\n            \"tzinfo\": self.site.tzinfo,\n            \"category_pages_descriptions\": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'],\n            \"category_pages_titles\": self.site.config['CATEGORY_PAGES_TITLES'],\n        }\n        context = {\n            \"title\": self.site.MESSAGES[lang][\"Categories\"],\n            \"description\": self.site.MESSAGES[lang][\"Categories\"],\n            \"pagekind\": [\"list\", \"tags_page\"],\n        }\n        kw.update(context)\n        return context, kw\n\n    def provide_context_and_uptodate(self, cat, lang, node=None):\n        \"\"\"Provide data for the context and the uptodate list for the list of the given classifiation.\"\"\"\n        cat_path = self.extract_hierarchy(cat)\n        kw = {\n            'category_path': self.site.config['CATEGORY_PATH'],\n            'category_prefix': self.site.config['CATEGORY_PREFIX'],\n            \"category_pages_are_indexes\": self.site.config['CATEGORY_PAGES_ARE_INDEXES'],\n            \"tzinfo\": self.site.tzinfo,\n            \"category_pages_descriptions\": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'],\n            \"category_pages_titles\": self.site.config['CATEGORY_PAGES_TITLES'],\n        }\n        posts = self.site.posts_per_classification[self.classification_name][lang]\n        children = [child for child in node.children if len([post for post in posts.get(child.classification_name, []) if self.site.config['SHOW_UNTRANSLATED_POSTS'] or post.is_translation_available(lang)]) > 0]\n        subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang), child.classification_name, child.classification_path) for child in children]\n        friendly_name = self.get_classification_friendly_name(cat, lang)\n        context = {\n            \"title\": self.site.config['CATEGORY_PAGES_TITLES'].get(lang, {}).get(cat, self.site.MESSAGES[lang][\"Posts about %s\"] % friendly_name),\n            \"description\": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'].get(lang, {}).get(cat),\n            \"kind\": \"category\",\n            \"pagekind\": [\"tag_page\", \"index\" if self.show_list_as_index else \"list\"],\n            \"tag\": friendly_name,\n            \"category\": cat,\n            \"category_path\": cat_path,\n            \"subcategories\": subcats,\n        }\n        if self.show_list_as_index:\n            context[\"rss_link\"] = \"\"\"<link rel=\"alternate\" type=\"application/rss+xml\" type=\"application/rss+xml\" title=\"RSS for tag {0} ({1})\" href=\"{2}\">\"\"\".format(friendly_name, lang, self.site.link(\"category_rss\", cat, lang))\n        kw.update(context)\n        return context, kw\n", "path": "nikola/plugins/task/categories.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright \u00a9 2012-2017 Roberto Alsina and others.\n\n# Permission is hereby granted, free of charge, to any\n# person obtaining a copy of this software and associated\n# documentation files (the \"Software\"), to deal in the\n# Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the\n# Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice\n# shall be included in all copies or substantial portions of\n# the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\n# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\"\"\"Render the category pages and feeds.\"\"\"\n\nfrom __future__ import unicode_literals\n\nfrom nikola.plugin_categories import Taxonomy\nfrom nikola import utils\n\n\nclass ClassifyCategories(Taxonomy):\n    \"\"\"Classify the posts by categories.\"\"\"\n\n    name = \"classify_categories\"\n\n    classification_name = \"category\"\n    overview_page_variable_name = \"categories\"\n    overview_page_items_variable_name = \"cat_items\"\n    overview_page_hierarchy_variable_name = \"cat_hierarchy\"\n    more_than_one_classifications_per_post = False\n    has_hierarchy = True\n    include_posts_from_subhierarchies = True\n    include_posts_into_hierarchy_root = False\n    show_list_as_subcategories_list = False\n    generate_atom_feeds_for_post_lists = True\n    template_for_classification_overview = \"tags.tmpl\"\n    always_disable_rss = False\n    apply_to_posts = True\n    apply_to_pages = False\n    minimum_post_count_per_classification_in_overview = 1\n    omit_empty_classifications = True\n    also_create_classifications_from_other_languages = True\n    path_handler_docstrings = {\n        'category_index': \"\"\"A link to the category index.\n\nExample:\n\nlink://category_index => /categories/index.html\"\"\",\n        'category': \"\"\"A link to a category. Takes page number as optional keyword argument.\n\nExample:\n\nlink://category/dogs => /categories/dogs.html\"\"\",\n        'category_atom': \"\"\"A link to a category's Atom feed.\n\nExample:\n\nlink://category_atom/dogs => /categories/dogs.atom\"\"\",\n        'category_rss': \"\"\"A link to a category's RSS feed.\n\nExample:\n\nlink://category_rss/dogs => /categories/dogs.xml\"\"\",\n    }\n\n    def set_site(self, site):\n        \"\"\"Set site, which is a Nikola instance.\"\"\"\n        super(ClassifyCategories, self).set_site(site)\n        self.show_list_as_index = self.site.config['CATEGORY_PAGES_ARE_INDEXES']\n        self.template_for_single_list = \"tagindex.tmpl\" if self.show_list_as_index else \"tag.tmpl\"\n\n    def is_enabled(self, lang=None):\n        \"\"\"Return True if this taxonomy is enabled, or False otherwise.\"\"\"\n        return True\n\n    def classify(self, post, lang):\n        \"\"\"Classify the given post for the given language.\"\"\"\n        cat = post.meta('category', lang=lang).strip()\n        return [cat] if cat else []\n\n    def get_classification_friendly_name(self, classification, lang, only_last_component=False):\n        \"\"\"Extract a friendly name from the classification.\"\"\"\n        classification = self.extract_hierarchy(classification)\n        return classification[-1] if classification else ''\n\n    def get_overview_path(self, lang, dest_type='page'):\n        \"\"\"A path handler for the list of all classifications.\"\"\"\n        if self.site.config['CATEGORIES_INDEX_PATH'](lang):\n            path = self.site.config['CATEGORIES_INDEX_PATH'](lang)\n            if path.endswith('/index'):  # TODO: remove in v8\n                utils.LOGGER.warn(\"CATEGORIES_INDEX_PATH for language {0} is missing a .html extension. Please update your configuration!\".format(lang))\n                path += '.html'\n            return [_f for _f in [path] if _f], 'never'\n        else:\n            return [_f for _f in [self.site.config['CATEGORY_PATH'](lang)] if _f], 'always'\n\n    def slugify_tag_name(self, name, lang):\n        \"\"\"Slugify a tag name.\"\"\"\n        if self.site.config['SLUG_TAG_PATH']:\n            name = utils.slugify(name, lang)\n        return name\n\n    def slugify_category_name(self, path, lang):\n        \"\"\"Slugify a category name.\"\"\"\n        if lang is None:  # TODO: remove in v8\n            utils.LOGGER.warn(\"ClassifyCategories.slugify_category_name() called without language!\")\n            lang = ''\n        if self.site.config['CATEGORY_OUTPUT_FLAT_HIERARCHY']:\n            path = path[-1:]  # only the leaf\n        result = [self.slugify_tag_name(part, lang) for part in path]\n        result[0] = self.site.config['CATEGORY_PREFIX'] + result[0]\n        if not self.site.config['PRETTY_URLS']:\n            result = ['-'.join(result)]\n        return result\n\n    def get_path(self, classification, lang, dest_type='page'):\n        \"\"\"A path handler for the given classification.\"\"\"\n        return [_f for _f in [self.site.config['CATEGORY_PATH'](lang)] if _f] + self.slugify_category_name(classification, lang), 'auto'\n\n    def extract_hierarchy(self, classification):\n        \"\"\"Given a classification, return a list of parts in the hierarchy.\"\"\"\n        return utils.parse_escaped_hierarchical_category_name(classification)\n\n    def recombine_classification_from_hierarchy(self, hierarchy):\n        \"\"\"Given a list of parts in the hierarchy, return the classification string.\"\"\"\n        return utils.join_hierarchical_category_path(hierarchy)\n\n    def provide_overview_context_and_uptodate(self, lang):\n        \"\"\"Provide data for the context and the uptodate list for the list of all classifiations.\"\"\"\n        kw = {\n            'category_path': self.site.config['CATEGORY_PATH'],\n            'category_prefix': self.site.config['CATEGORY_PREFIX'],\n            \"category_pages_are_indexes\": self.site.config['CATEGORY_PAGES_ARE_INDEXES'],\n            \"tzinfo\": self.site.tzinfo,\n            \"category_pages_descriptions\": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'],\n            \"category_pages_titles\": self.site.config['CATEGORY_PAGES_TITLES'],\n        }\n        context = {\n            \"title\": self.site.MESSAGES[lang][\"Categories\"],\n            \"description\": self.site.MESSAGES[lang][\"Categories\"],\n            \"pagekind\": [\"list\", \"tags_page\"],\n        }\n        kw.update(context)\n        return context, kw\n\n    def provide_context_and_uptodate(self, cat, lang, node=None):\n        \"\"\"Provide data for the context and the uptodate list for the list of the given classifiation.\"\"\"\n        cat_path = self.extract_hierarchy(cat)\n        kw = {\n            'category_path': self.site.config['CATEGORY_PATH'],\n            'category_prefix': self.site.config['CATEGORY_PREFIX'],\n            \"category_pages_are_indexes\": self.site.config['CATEGORY_PAGES_ARE_INDEXES'],\n            \"tzinfo\": self.site.tzinfo,\n            \"category_pages_descriptions\": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'],\n            \"category_pages_titles\": self.site.config['CATEGORY_PAGES_TITLES'],\n        }\n        posts = self.site.posts_per_classification[self.classification_name][lang]\n        children = [child for child in node.children if len([post for post in posts.get(child.classification_name, []) if self.site.config['SHOW_UNTRANSLATED_POSTS'] or post.is_translation_available(lang)]) > 0]\n        subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang)) for child in children]\n        friendly_name = self.get_classification_friendly_name(cat, lang)\n        context = {\n            \"title\": self.site.config['CATEGORY_PAGES_TITLES'].get(lang, {}).get(cat, self.site.MESSAGES[lang][\"Posts about %s\"] % friendly_name),\n            \"description\": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'].get(lang, {}).get(cat),\n            \"kind\": \"category\",\n            \"pagekind\": [\"tag_page\", \"index\" if self.show_list_as_index else \"list\"],\n            \"tag\": friendly_name,\n            \"category\": cat,\n            \"category_path\": cat_path,\n            \"subcategories\": subcats,\n        }\n        if self.show_list_as_index:\n            context[\"rss_link\"] = \"\"\"<link rel=\"alternate\" type=\"application/rss+xml\" type=\"application/rss+xml\" title=\"RSS for tag {0} ({1})\" href=\"{2}\">\"\"\".format(friendly_name, lang, self.site.link(\"category_rss\", cat, lang))\n        kw.update(context)\n        return context, kw\n", "path": "nikola/plugins/task/categories.py"}]}