Skip to content
Permalink
Browse files

v8/category_prevnext replaces v7/section_prevnext

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 5, 2018
1 parent c0918c7 commit 70f28b8c47a8292bbd5ce90f5848aa8767039a3a
@@ -1,3 +1,5 @@
**For Nikola v8, this plugin has been replaced by `category_prevnext`.**

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.

@@ -0,0 +1,13 @@
This plugin changes the previous/next links below the posts to reflect the category index instead of the global index.
This way, the categories 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", "", "page.tmpl"),
)

and creating a corresponding pages/index.md file.

This plugin replaces `section_prevnext` from v7.
@@ -0,0 +1,13 @@
[Core]
name = category_prevnext
module = category_prevnext

[Documentation]
author = Alexander Krimm
version = 0.1
website = https://plugins.getnikola.com/v8/category_prevnext?
description = Sets next/previous link according to category index instead of global timeline

[Nikola]
PluginCategory = SignalHandler
MinVersion = 8.0.0
@@ -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 category"""

from __future__ import unicode_literals
import blinker

from nikola.plugin_categories import SignalHandler


class CategoryNav(SignalHandler):
"""Change navigation links below posts to next/previous post in category"""

name = "category"

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['category'].items():
for category, categoryposts in langposts.items():
for i, p in enumerate(categoryposts[1:]):
p.next_post = categoryposts[i]
for i, p in enumerate(categoryposts[:-1]):
p.prev_post = categoryposts[i + 1]
categoryposts[0].next_post = None
categoryposts[-1].prev_post = None

def set_site(self, site):
"""Set site, which is a Nikola instance."""
super(CategoryNav, self).set_site(site)
# Add hook for after taxonomies_classifier has set site.posts_per_classification
blinker.signal("taxonomies_classified").connect(self._set_navlinks)

0 comments on commit 70f28b8

Please sign in to comment.
You can’t perform that action at this time.