Files
Talha Mansoor 073c997eea Fix an issue in neighbors plugin which was introduced after subcategory support
It is not necessary that articles will have subcategories. You may
end up getting following critical error.

>
CRITICAL: ("'ArticlesGenerator' object has no attribute 'subcategories'",)
CRITICAL: 'ArticlesGenerator' object has no attribute 'subcategories'
Traceback (most recent call last):
  File "/Users/talha/Repos/VirtualEnvs/pelican-dev/bin/pelican", line 8, in <module>
    load_entry_point('pelican==3.3', 'console_scripts', 'pelican')()
  File "/Users/talha/Repos/VirtualEnvs/pelican-dev/lib/python2.7/site-packages/pelican-3.3-py2.7.egg/pelican/__init__.py", line 346, in main
    pelican.run()
  File "/Users/talha/Repos/VirtualEnvs/pelican-dev/lib/python2.7/site-packages/pelican-3.3-py2.7.egg/pelican/__init__.py", line 162, in run
    p.generate_context()
  File "/Users/talha/Repos/VirtualEnvs/pelican-dev/lib/python2.7/site-packages/pelican-3.3-py2.7.egg/pelican/generators.py", line 480, in generate_context
    signals.article_generator_finalized.send(self)
  File "/Users/talha/Repos/VirtualEnvs/pelican-dev/lib/python2.7/site-packages/blinker/base.py", line 267, in send
    for receiver in self.receivers_for(sender)]
  File "/Users/talha/Repos/pelican-plugins/neighbors/neighbors.py", line 49, in neighbors
    for subcategory, articles in generator.subcategories:
AttributeError: 'ArticlesGenerator' object has no attribute 'subcategories'
2014-02-07 11:40:48 +05:00
..

Neighbor Articles Plugin for Pelican
====================================

This plugin adds ``next_article`` (newer) and ``prev_article`` (older) 
variables to the article's context.

Also adds ``next_article_in_category`` and ``prev_article_in_category``.


Usage
-----

.. code-block:: html+jinja

    <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 %}
        <li>
            <a href="{{ SITEURL }}/{{ article.next_article_in_category.url}}">
                {{ article.next_article_in_category.title }}
            </a>
        </li>
    {% endif %}
    </ul> 

Usage with the Subcategory plugin
---------------------------------

If you want to get the neigbors within a subcategory it's a little different.
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 Foo/Bar. 
Therefor the usage with subcategories is:

.. code-block:: html+jinja

    <ul>
    {% if article.prev_article_subcategory1 %}
        <li>
            <a href="{{ SITEURL }}/{{ article.prev_article_in_subcategory1.url}}">
                {{ article.prev_article_in_subcategory1.title }}
            </a>
        </li>
    {% endif %}
    {% if article.next_article %}
        <li>
            <a href="{{ SITEURL }}/{{ article.next_article_subcategory1.url}}">
                {{ article.next_article_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 %}
        <li>
            <a href="{{ SITEURL }}/{{ article.next_article_in_subcategory2.url}}">
                {{ article.next_article_in_subcategory2.title }}
            </a>
        </li>
    {% endif %}
    </ul>