Giter Club home page Giter Club logo

neighbors's Introduction

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 Neighbors 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:

  • sebcategory0 is foo
  • subcategory1 will be foo/bar
  • subcategory2 will be foo/bar/baz

Subcategory plugin support

You can use Neighbors 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 subcategory or more_categories 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>

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.

neighbors's People

Contributors

alistairmagee avatar avaris avatar botpub avatar calfzhou avatar davidag avatar johnmathews avatar jorgesumle avatar justinmayer avatar kdeldycke avatar lucas-c avatar sg-phimeca avatar talha131 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.