Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin to change previous/next post to reflect section indices instead of global index #204

Merged
merged 8 commits into from Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions 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.
13 changes: 13 additions & 0 deletions 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that isn’t going to be the URL anymore. You can use your own homepage here, or whatever else.

description = Sets next/previous link according to section index instead of global timeline

[Nikola]
PluginCategory = SignalHandler
MinVersion = 7.8.2
58 changes: 58 additions & 0 deletions 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)