Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
v8/category_prevnext replaces v7/section_prevnext
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |