diff --git a/v7/section_prevnext/README.md b/v7/section_prevnext/README.md new file mode 100644 index 00000000..7ab94ff5 --- /dev/null +++ b/v7/section_prevnext/README.md @@ -0,0 +1,13 @@ +This plugin changes the previous/next links below the posts to reflect the section index instead of the global index. +This way, the sections of a blog behave more like independent subblogs. + +There is no configuration needed, but i recommend to replace the blog index by a static page to avoid confusing readers. +This can be archived by setting INDEX\_PATH to some subdirectory, adding pages output to the root directory + + PAGES = ( + ("pages/*.md", "", "story.tmpl"), + ) + +and creating a corresponding pages/index.md file. + +Depends on taxonomies introduced in Nikola 7.8.2 so be sure to use a recent version. diff --git a/v7/section_prevnext/section_prevnext.plugin b/v7/section_prevnext/section_prevnext.plugin new file mode 100644 index 00000000..64e39525 --- /dev/null +++ b/v7/section_prevnext/section_prevnext.plugin @@ -0,0 +1,13 @@ +[Core] +name = section_prevnext +module = section_prevnext + +[Documentation] +author = Alexander Krimm +version = 0.1 +website = https://plugins.getnikola.com/#section_prevnext +description = Sets next/previous link according to section index instead of global timeline + +[Nikola] +PluginCategory = SignalHandler +MinVersion = 7.8.2 diff --git a/v7/section_prevnext/section_prevnext.py b/v7/section_prevnext/section_prevnext.py new file mode 100644 index 00000000..c6c8a5c4 --- /dev/null +++ b/v7/section_prevnext/section_prevnext.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +# Copyright © 2017 Alexander Krimm. + +# Permission is hereby granted, free of charge, to any +# person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the +# Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the +# Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice +# shall be included in all copies or substantial portions of +# the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""Change navigation links below posts to next/previous post in section""" + +from __future__ import unicode_literals +import blinker + +from nikola.plugin_categories import SignalHandler + + +class SectionNav(SignalHandler): + """Change navigation links below posts to next/previous post in section""" + + name = "section_prevnext" + + def _set_navlinks(self, site): + # Needed to avoid strange errors during tests + if site is not self.site: + return + # Update prev_post and next_post + for lang, langposts in site.posts_per_classification['section_index'].items(): + for section, sectionposts in langposts.items(): + for i, p in enumerate(sectionposts[1:]): + p.next_post = sectionposts[i] + for i, p in enumerate(sectionposts[:-1]): + p.prev_post = sectionposts[i + 1] + sectionposts[0].next_post = None + sectionposts[-1].prev_post = None + + def set_site(self, site): + """Set site, which is a Nikola instance.""" + super(SectionNav, self).set_site(site) + # Add hook for after taxonomies_classifier has set site.posts_per_classification + blinker.signal("taxonomies_classified").connect(self._set_navlinks)