aboutsummaryrefslogtreecommitdiff
path: root/plugins/related_posts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/related_posts')
-rw-r--r--plugins/related_posts/Readme.rst38
-rw-r--r--plugins/related_posts/__init__.py2
-rw-r--r--[-rwxr-xr-x]plugins/related_posts/related_posts.py11
3 files changed, 44 insertions, 7 deletions
diff --git a/plugins/related_posts/Readme.rst b/plugins/related_posts/Readme.rst
new file mode 100644
index 0000000..0edf4bd
--- /dev/null
+++ b/plugins/related_posts/Readme.rst
@@ -0,0 +1,38 @@
+Related posts
+-------------
+
+**NOTE:** `This plugin has been moved to its own repository <https://github.com/pelican-plugins/related-posts>`_. Please file any issues/PRs there. Once all plugins have been migrated to the `new Pelican Plugins organization <https://github.com/pelican-plugins>`_, this monolithic repository will be archived.
+
+-------------------------------------------------------------------------------
+
+This plugin adds the ``related_posts`` variable to the article's context.
+By default, up to 5 articles are listed. You can customize this value by
+defining ``RELATED_POSTS_MAX`` in your settings file::
+
+ RELATED_POSTS_MAX = 10
+
+You can then use the ``article.related_posts`` variable in your templates.
+For example::
+
+ {% if article.related_posts %}
+ <ul>
+ {% for related_post in article.related_posts %}
+ <li><a href="{{ SITEURL }}/{{ related_post.url }}">{{ related_post.title }}</a></li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+
+
+Your related posts should share a common tag. You can also use ``related_posts:`` in your post's meta data.
+The 'related_posts:' meta data works together with your existing slugs::
+
+ related_posts: slug1, slug2, slug3, ... slugN
+
+``N`` represents the ``RELATED_POSTS_MAX``.
+
+Additionally, you can specify::
+
+ RELATED_POSTS_SKIP_SAME_CATEGORY = True
+
+in your settings file. With this setting, ``article.related_posts`` will
+contain only related posts from categories other than the original article's.
diff --git a/plugins/related_posts/__init__.py b/plugins/related_posts/__init__.py
index c78861e..057540e 100644
--- a/plugins/related_posts/__init__.py
+++ b/plugins/related_posts/__init__.py
@@ -1 +1 @@
-from .related_posts import *
+from .related_posts import *
diff --git a/plugins/related_posts/related_posts.py b/plugins/related_posts/related_posts.py
index a0cfa15..fbb2426 100755..100644
--- a/plugins/related_posts/related_posts.py
+++ b/plugins/related_posts/related_posts.py
@@ -14,15 +14,14 @@ def add_related_posts(generator):
# get the max number of entries from settings
# or fall back to default (5)
numentries = generator.settings.get('RELATED_POSTS_MAX', 5)
- ignore_tags = generator.settings.get('RELATED_POSTS_IGNORE_TAGS', [])
# Skip all posts in the same category as the article
skipcategory = generator.settings.get('RELATED_POSTS_SKIP_SAME_CATEGORY', False)
- for article in generator.articles:
+ for article in chain(generator.articles, generator.drafts):
# set priority in case of forced related posts
if hasattr(article,'related_posts'):
- # split slugs
+ # split slugs
related_posts = article.related_posts.split(',')
- posts = []
+ posts = []
# get related articles
for slug in related_posts:
i = 0
@@ -41,7 +40,7 @@ def add_related_posts(generator):
continue
# score = number of common tags
- related = chain(*(generator.tags[tag] for tag in article.tags if tag.name not in ignore_tags))
+ related = chain(*(generator.tags[tag] for tag in article.tags))
if skipcategory:
related = (other for other in related
if other.category != article.category)
@@ -50,7 +49,7 @@ def add_related_posts(generator):
# remove itself
scores.pop(article, None)
- article.related_posts = [other for other, count
+ article.related_posts = [other for other, count
in scores.most_common(numentries)]
def register():