Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # (c) 2016 t.animal licensed under GPL v3
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- from __future__ import unicode_literals, print_function
- from nikola.plugin_categories import ConfigPlugin
- import nikola
- class MetaNavigation(ConfigPlugin):
- """Adds some meta information to the GLOBAL_CONTEXT variable
- for access in themes.
- """
- name = 'metanavigation'
- def set_site(self, site):
- site.scan_posts()
- metaNavDict = {}
- if "META_NAV_SECTIONWISE" in site.GLOBAL_CONTEXT and \
- site.GLOBAL_CONTEXT["META_NAV_SECTIONWISE"] and site.config["POSTS_SECTIONS"]:
- availableSections = list(set([post.section_slug() for post in site.all_posts]))
- metaNavDict["available_sections"] = availableSections
- for section in availableSections:
- #this collides if a section is called available_sections :(
- metaNavDict[section] = {
- "years": [x for x in site.posts_per_year if any(filter(lambda p: p.section_slug() == section, site.posts_per_year[x]))],
- "categories": [x for x in site.posts_per_category if any(filter(lambda p: p.section_slug() == section, site.posts_per_category[x]))],
- "tags": [x for x in site.posts_per_tag if any(filter(lambda p: p.section_slug() == section, site.posts_per_category[x]))],
- "section_description": site.config["POSTS_SECTION_DESCRIPTIONS"][nikola.utils.LocaleBorg().current_lang]
- }
- else:
- metaNavDict = {
- "years": [x for x in site.posts_per_year],
- "categories": [x for x in site.posts_per_category],
- "tags": [x for x in site.posts_per_tag]
- }
- if site.config["POSTS_SECTIONS"]:
- metaNavDict["section_description"] = site.config["POSTS_SECTION_DESCRIPTIONS"][nikola.utils.LocaleBorg().current_lang]
- site.GLOBAL_CONTEXT["metanavigation"] = metaNavDict
- super(MetaNavigation, self).set_site(site)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement