From cb8c02781b5a7a71c579fa237b369ba4e446703a Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 25 Mar 2015 15:28:44 +0100 Subject: Updated related post plugin for ignoring a tag --- pelicanconf.py | 2 ++ plugins/related_posts/related_posts.py | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) mode change 100644 => 100755 plugins/related_posts/related_posts.py 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 old mode 100644 new mode 100755 index dff03c5..a0cfa15 --- 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) -- cgit v1.2.3