From 3fcddf78f965a2c5ee0a9602708899fb0e72a7c0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sat, 21 Mar 2015 11:32:09 +0100 Subject: Article on sailfish developpement --- plugins/related_posts/related_posts.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) mode change 100644 => 100755 plugins/related_posts/related_posts.py (limited to 'plugins/related_posts') 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