Skip to main content

Neighbor Articles: A Plugin for Pelican

Build Status PyPI Version

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 is foo
  • subcategory1 will be foo/bar
  • subcategory2 will be foo/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.

Release files for pelican-neighbors 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pelican-neighbors 1.2.0
File Size Uploaded
pelican-neighbors-1.2.0.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pelican-neighbors 1.2.0
File Interpreter ABI Platform
pelican_neighbors-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.6 kB

Release files / pelican-neighbors-1.2.0.tar.gz

Download URL pelican-neighbors-1.2.0.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1cbeee08f4d2e135452c044924c3f8e5e39ff083dcfb7485e8eeafdab9d2e445
BLAKE2b-256 checksum
How to use checksums
31e1d5dfde3080c9ef32984da5001ecdec181d135013edeef2931532d7dcd855
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.7.10 Linux/5.4.0-1046-azure

Release files / pelican_neighbors-1.2.0-py3-none-any.whl

Download URL pelican_neighbors-1.2.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
963df1d27dd8b34ac7b85320e63184d3f4e396e4570a3d49f5911246387a35bb
BLAKE2b-256 checksum
How to use checksums
8dadf2ad5fa3c1d35681707cf809a4573dda85a67dac007c59ff9371dae87b29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.7.10 Linux/5.4.0-1046-azure

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page