mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
More changes to related_posts
This commit is contained in:
parent
a0812eeb17
commit
53a1c21a98
1 changed files with 8 additions and 11 deletions
|
|
@ -349,20 +349,16 @@ class ArticlesGenerator(Generator):
|
||||||
for article in self.articles:
|
for article in self.articles:
|
||||||
article.related_posts = []
|
article.related_posts = []
|
||||||
relation_score = {}
|
relation_score = {}
|
||||||
if article.tags:
|
try:
|
||||||
article_tags = article.tags
|
article_tags = article.tags
|
||||||
for tag in article_tags:
|
for tag in article_tags:
|
||||||
try:
|
for related_article in self.tags[tag]:
|
||||||
for related_article in self.tags[tag]:
|
article.related_posts.append(related_article)
|
||||||
article.related_posts.append(related_article)
|
article.related_posts.reverse()
|
||||||
article.related_posts.reverse()
|
|
||||||
|
|
||||||
except:
|
except: # can't find any related posts
|
||||||
article.related_posts = potential_related[:5]
|
pass
|
||||||
|
#article.related_posts = all_articles[:5].reverse()
|
||||||
elif len(article.related_posts) == 0: # article doesn't have tags
|
|
||||||
print "No tags for ", article.title
|
|
||||||
article.related_posts = all_articles[:5].reverse()
|
|
||||||
|
|
||||||
relation_score = dict( \
|
relation_score = dict( \
|
||||||
zip(set(article.related_posts), \
|
zip(set(article.related_posts), \
|
||||||
|
|
@ -370,6 +366,7 @@ class ArticlesGenerator(Generator):
|
||||||
set(article.related_posts))))
|
set(article.related_posts))))
|
||||||
|
|
||||||
ranked_related = sorted(relation_score, key=relation_score.get)
|
ranked_related = sorted(relation_score, key=relation_score.get)
|
||||||
|
|
||||||
article.related_posts = ranked_related
|
article.related_posts = ranked_related
|
||||||
|
|
||||||
try: # make sure article doesn't appear in its own related posts
|
try: # make sure article doesn't appear in its own related posts
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue