Skip to main content

Neighbors is a Pelican plugin that adds Next/Previous links to articles

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican-neighbors-1.2.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

pelican_neighbors-1.2.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

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

Hashes for pelican-neighbors-1.2.0.tar.gz
Algorithm Hash digest
SHA256 1cbeee08f4d2e135452c044924c3f8e5e39ff083dcfb7485e8eeafdab9d2e445
MD5 caa016cf3c4ab70b65ad4df181373c1b
BLAKE2b-256 31e1d5dfde3080c9ef32984da5001ecdec181d135013edeef2931532d7dcd855

See more details on using hashes here.

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

Hashes for pelican_neighbors-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 963df1d27dd8b34ac7b85320e63184d3f4e396e4570a3d49f5911246387a35bb
MD5 28944ab04b0737444a96d19c4ac8e01e
BLAKE2b-256 8dadf2ad5fa3c1d35681707cf809a4573dda85a67dac007c59ff9371dae87b29

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page