multi_part.py 990 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. from logging import warning
  11. warning_message = """multi_part plugin: this plugin has been deprecated.
  12. The 'series' plugin provides better support for multi part articles.
  13. """
  14. def aggregate_multi_part(generator):
  15. warning(warning_message)
  16. multi_part = defaultdict(list)
  17. for article in generator.articles:
  18. if 'parts' in article.metadata:
  19. multi_part[article.metadata['parts']].append(article)
  20. for part_id in multi_part:
  21. parts = multi_part[part_id]
  22. # Sort by date
  23. parts.sort(key=lambda x: x.metadata['date'])
  24. for article in parts:
  25. article.metadata['parts_articles'] = parts
  26. def register():
  27. signals.article_generator_finalized.connect(aggregate_multi_part)