Neighbors is a Pelican plugin that adds Next/Previous links to articles
Project description
Neighbor Articles: A Plugin for Pelican
Neighbors is a Pelican plugin that adds Next/Previous links to articles.
Installation
This plugin can be installed via:
python -m pip install pelican-neighbors
Usage
This plugin adds a couple of new variables to the article's context:
next_article
(newer)prev_article
(older)next_article_in_category
prev_article_in_category
next_article_in_subcategory#
prev_article_in_subcategory#
Here is an example on how to add article navigation in your Jinja article.html
template:
<ul>
{% if article.prev_article %}
<li>
<a href="{{ SITEURL }}/{{ article.prev_article.url}}">
{{ article.prev_article.title }}
</a>
</li>
{% endif %}
{% if article.next_article %}
<li>
<a href="{{ SITEURL }}/{{ article.next_article.url}}">
{{ article.next_article.title }}
</a>
</li>
{% endif %}
</ul>
<ul>
{% if article.prev_article_in_category %}
<li>
<a href="{{ SITEURL }}/{{ article.prev_article_in_category.url}}">
{{ article.prev_article_in_category.title }}
</a>
</li>
{% endif %}
{% if article.next_article_in_category %}
<li>
<a href="{{ SITEURL }}/{{ article.next_article_in_category.url}}">
{{ article.next_article_in_category.title }}
</a>
</li>
{% endif %}
</ul>
More Categories plugin support
You can use the Neighbors plugin with the More Categories plugin.
Since an article can belong to more than one subcategory, subcategories are
stored in a list. If you have an article with subcategories like
foo/bar/baz
, it will belong to both subcategory bar
and bar/baz
.
Subcategory neighbors are added to an article as next_article_in_subcategory#
and prev_article_in_subcategory#
, where #
is the level of subcategory.
Using the example above:
subcategory0
isfoo
subcategory1
will befoo/bar
subcategory2
will befoo/bar/baz
Subcategory plugin support
You can use the Neighbors plugin in conjunction with the Subcategory plugin.
Since an article can belong to more than one subcategory, subcategories are
stored in a list. If you have an article with subcategories like
Category/Foo/Bar
, it will belong to both subcategory Foo
, and Foo/Bar
.
Subcategory neighbors are added to an article as next_article_in_subcategory#
and prev_article_in_subcategory#
where #
is the level of subcategory. So
using the example from above, subcategory1
will be Foo
, and subcategory2
will be Foo/Bar
.
Template Examples
The usage with subcategories from either the Subcategory plugin or the More Categories plugin is:
<ul>
{% if article.prev_article_in_subcategory1 %}
<li>
<a href="{{ SITEURL }}/{{ article.prev_article_in_subcategory1.url}}">
{{ article.prev_article_in_subcategory1.title }}
</a>
</li>
{% endif %}
{% if article.next_article_in_subcategory1 %}
<li>
<a href="{{ SITEURL }}/{{ article.next_article_in_subcategory1.url}}">
{{ article.next_article_in_subcategory1.title }}
</a>
</li>
{% endif %}
</ul>
<ul>
{% if article.prev_article_in_subcategory2 %}
<li>
<a href="{{ SITEURL }}/{{ article.prev_article_in_subcategory2.url}}">
{{ article.prev_article_in_subcategory2.title }}
</a>
</li>
{% endif %}
{% if article.next_article_in_subcategory2 %}
<li>
<a href="{{ SITEURL }}/{{ article.next_article_in_subcategory2.url}}">
{{ article.next_article_in_subcategory2.title }}
</a>
</li>
{% endif %}
</ul>
Limitations
If an article has multiple categories, only the first category is considered.
Contributing
Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on existing issues.
To start contributing to this plugin, review the Contributing to Pelican documentation, beginning with the Contributing Code section.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pelican-neighbors-1.2.0.tar.gz
.
File metadata
- Download URL: pelican-neighbors-1.2.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.7.10 Linux/5.4.0-1046-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cbeee08f4d2e135452c044924c3f8e5e39ff083dcfb7485e8eeafdab9d2e445 |
|
MD5 | caa016cf3c4ab70b65ad4df181373c1b |
|
BLAKE2b-256 | 31e1d5dfde3080c9ef32984da5001ecdec181d135013edeef2931532d7dcd855 |
File details
Details for the file pelican_neighbors-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: pelican_neighbors-1.2.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.7.10 Linux/5.4.0-1046-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 963df1d27dd8b34ac7b85320e63184d3f4e396e4570a3d49f5911246387a35bb |
|
MD5 | 28944ab04b0737444a96d19c4ac8e01e |
|
BLAKE2b-256 | 8dadf2ad5fa3c1d35681707cf809a4573dda85a67dac007c59ff9371dae87b29 |