footer_insert.py 811 B

12345678910111213141516171819202122232425262728293031
  1. """
  2. Footer Insert
  3. """
  4. from pelican import signals
  5. from pelican.contents import Content, Article
  6. def add_footer(content):
  7. if not isinstance(content, Article):
  8. return
  9. if 'FOOTER_INSERT_HTML' not in content.settings:
  10. return
  11. data_dict = {
  12. 'title': content.title,
  13. 'url': content.url,
  14. 'author': content.author.name,
  15. 'authors': ','.join([x.name for x in content.authors]),
  16. 'slug': content.slug,
  17. 'category': content.category,
  18. 'summary': content.summary,
  19. }
  20. if hasattr(content, 'date'):
  21. data_dict['date'] = content.date
  22. foot_insert_html = content.settings['FOOTER_INSERT_HTML'] % data_dict
  23. content.footer_insert_html = foot_insert_html
  24. def register():
  25. signals.content_object_init.connect(add_footer)