summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2015-03-25 15:28:44 +0100
committerSébastien Dailly <sebastien@chimrod.com>2015-03-25 15:28:44 +0100
commitcb8c02781b5a7a71c579fa237b369ba4e446703a (patch)
treec006b3f9b056a8c6184b4e7988aa9bc9f7e286e3
parent13778732313df978dd9fa8b88c0db6cef0ba7a54 (diff)
Updated related post plugin for ignoring a tag
-rwxr-xr-xpelicanconf.py2
-rwxr-xr-x[-rw-r--r--]plugins/related_posts/related_posts.py11
2 files changed, 8 insertions, 5 deletions
diff --git a/pelicanconf.py b/pelicanconf.py
index a6da2bf..c31ac2c 100755
--- a/pelicanconf.py
+++ b/pelicanconf.py
@@ -54,6 +54,8 @@ PLUGIN_PATHS = ['plugins']
PLUGINS = ['related_posts', 'typogrify']
+RELATED_POSTS_IGNORE_TAGS = ["Libre"]
+
SUMMARY_MAX_LENGTH=100
DOCUTILS_SETTINGS={
diff --git a/plugins/related_posts/related_posts.py b/plugins/related_posts/related_posts.py
index dff03c5..a0cfa15 100644..100755
--- a/plugins/related_posts/related_posts.py
+++ b/plugins/related_posts/related_posts.py
@@ -14,14 +14,15 @@ 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:
# 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
@@ -40,7 +41,7 @@ def add_related_posts(generator):
continue
# score = number of common tags
- related = chain(*(generator.tags[tag] for tag in article.tags))
+ related = chain(*(generator.tags[tag] for tag in article.tags if tag.name not in ignore_tags))
if skipcategory:
related = (other for other in related
if other.category != article.category)
@@ -49,8 +50,8 @@ 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():
- signals.article_generator_finalized.connect(add_related_posts) \ No newline at end of file
+ signals.article_generator_finalized.connect(add_related_posts)