multi_part.py 826 B

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. """
  3. Copyright (c) FELD Boris <lothiraldan@gmail.com>
  4. Multiple part support
  5. =====================
  6. Create a navigation menu for multi-part related_posts
  7. """
  8. from collections import defaultdict
  9. from pelican import signals
  10. def aggregate_multi_part(generator):
  11. multi_part = defaultdict(list)
  12. for article in generator.articles:
  13. if 'parts' in article.metadata:
  14. multi_part[article.metadata['parts']].append(article)
  15. for part_id in multi_part:
  16. parts = multi_part[part_id]
  17. # Sort by date
  18. parts.sort(key=lambda x: x.metadata['date'])
  19. for article in parts:
  20. article.metadata['parts_articles'] = parts
  21. def register():
  22. signals.article_generator_finalized.connect(aggregate_multi_part)