1234567891011121314151617181920212223242526272829303132333435 |
- """
- Related posts plugin for Pelican
- ================================
- Adds related_posts variable to article's context
- """
- from pelican import signals
- from collections import Counter
- def add_related_posts(generator):
-
-
- numentries = generator.settings.get('RELATED_POSTS_MAX', 5)
- for article in generator.articles:
-
- if not hasattr(article, 'tags'):
- continue
-
- scores = Counter()
- for tag in article.tags:
- scores += Counter(generator.tags[tag])
-
- scores.pop(article)
- article.related_posts = [other for other, count
- in scores.most_common(numentries)]
- def register():
- signals.article_generator_finalized.connect(add_related_posts)
|