mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
pep8-ify
This commit is contained in:
parent
e92937eea0
commit
1e7c939953
1 changed files with 10 additions and 9 deletions
|
|
@ -8,8 +8,8 @@ Adds related_posts variable to article's context
|
|||
|
||||
Settings
|
||||
--------
|
||||
To enable, add
|
||||
|
||||
To enable, add
|
||||
|
||||
from pelican.plugins import related_posts
|
||||
PLUGINS = [related_posts]
|
||||
|
||||
|
|
@ -29,23 +29,24 @@ Usage
|
|||
"""
|
||||
|
||||
related_posts = []
|
||||
|
||||
|
||||
def add_related_posts(generator, metadata):
|
||||
if 'tags' in metadata:
|
||||
for tag in metadata['tags']:
|
||||
#print tag
|
||||
for related_article in generator.tags[tag]:
|
||||
related_posts.append(related_article)
|
||||
|
||||
|
||||
if len(related_posts) < 1:
|
||||
return
|
||||
|
||||
relation_score = dict( \
|
||||
zip(set(related_posts), \
|
||||
map(related_posts.count, \
|
||||
set(related_posts))))
|
||||
|
||||
relation_score = dict(zip(set(related_posts), map(related_posts.count,
|
||||
set(related_posts))))
|
||||
ranked_related = sorted(relation_score, key=relation_score.get)
|
||||
|
||||
|
||||
metadata["related_posts"] = ranked_related[:5]
|
||||
|
||||
|
||||
def register():
|
||||
signals.article_generate_context.connect(add_related_posts)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue