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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d454236
add Plugin to change navigation links in posts
wirew0rm 6b4923d
Listen for the right event and minor fixes
wirew0rm 9d1ec67
Add README
wirew0rm fe8f5ab
Add version depencency.
wirew0rm 644a6b0
clarify readme
wirew0rm b02f52d
Fix flake8 error
wirew0rm 64551b0
Fix flake8
wirew0rm 41219d5
Fix docstrings, authorship and debug output
wirew0rm File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 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. |
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 = 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 |
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 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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.