Advertisement
t_animal

Untitled

Oct 17th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. #    (c) 2016 t.animal licensed under GPL v3
  4.  
  5. #    This program is free software: you can redistribute it and/or modify
  6. #    it under the terms of the GNU General Public License as published by
  7. #    the Free Software Foundation, either version 3 of the License, or
  8. #    (at your option) any later version.
  9.  
  10. #    This program is distributed in the hope that it will be useful,
  11. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #    GNU General Public License for more details.
  14.  
  15. #    You should have received a copy of the GNU General Public License
  16. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  
  18.  
  19. from __future__ import unicode_literals, print_function
  20. from nikola.plugin_categories import ConfigPlugin
  21.  
  22. import nikola
  23.  
  24.  
  25. class MetaNavigation(ConfigPlugin):
  26.     """Adds some meta information to the GLOBAL_CONTEXT variable
  27.        for access in themes.
  28.     """
  29.  
  30.     name = 'metanavigation'
  31.  
  32.     def set_site(self, site):
  33.         site.scan_posts()
  34.  
  35.         metaNavDict = {}
  36.  
  37.         if "META_NAV_SECTIONWISE" in site.GLOBAL_CONTEXT and \
  38.             site.GLOBAL_CONTEXT["META_NAV_SECTIONWISE"] and site.config["POSTS_SECTIONS"]:
  39.  
  40.             availableSections = list(set([post.section_slug() for post in site.all_posts]))
  41.             metaNavDict["available_sections"] = availableSections
  42.  
  43.             for section in availableSections:
  44.                 #this collides if a section is called available_sections :(
  45.                 metaNavDict[section] = {
  46.                     "years": [x for x in site.posts_per_year if any(filter(lambda p: p.section_slug() == section, site.posts_per_year[x]))],
  47.                     "categories": [x for x in site.posts_per_category if any(filter(lambda p: p.section_slug() == section, site.posts_per_category[x]))],
  48.                     "tags": [x for x in site.posts_per_tag if any(filter(lambda p: p.section_slug() == section, site.posts_per_category[x]))],
  49.                     "section_description":  site.config["POSTS_SECTION_DESCRIPTIONS"][nikola.utils.LocaleBorg().current_lang]
  50.                 }
  51.  
  52.         else:
  53.             metaNavDict = {
  54.                     "years": [x for x in site.posts_per_year],
  55.                     "categories": [x for x in site.posts_per_category],
  56.                     "tags": [x for x in site.posts_per_tag]
  57.             }
  58.  
  59.             if site.config["POSTS_SECTIONS"]:
  60.                 metaNavDict["section_description"] = site.config["POSTS_SECTION_DESCRIPTIONS"][nikola.utils.LocaleBorg().current_lang]
  61.  
  62.         site.GLOBAL_CONTEXT["metanavigation"] = metaNavDict
  63.  
  64.         super(MetaNavigation, self).set_site(site)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement