Browse Source

Merge pull request #304 from alswl/feature/footer_insert

Feature/footer insert
Alexis Metaireau 10 years ago
parent
commit
aedab367f1
3 changed files with 48 additions and 0 deletions
  1. 17 0
      footer_insert/README.md
  2. 1 0
      footer_insert/__init__.py
  3. 30 0
      footer_insert/footer_insert.py

+ 17 - 0
footer_insert/README.md

@@ -0,0 +1,17 @@
+# Footer Insert
+
+This plugin allows you to insert a `FOOTER_INSERT_HTML` to the end of the blog.
+
+eg.  add authors / blog infomation to every blog.
+
+## Usage
+
+1. Insert `FOOTER_INSERT_HTML` to your `pelicanconf.py`. You can use
+title / url / author / authors / slug / category / summary
+/ date infomation in the config like this: `%(title)s`.
+2. Insert this code to your artical template file, eg. `templates/article.html`:
+```
+{% if article.footer_insert_html %}
+  {{ article.footer_insert_html }}
+{% endif %}
+```

+ 1 - 0
footer_insert/__init__.py

@@ -0,0 +1 @@
+from .footer_insert import *

+ 30 - 0
footer_insert/footer_insert.py

@@ -0,0 +1,30 @@
+"""
+Footer Insert
+"""
+
+from pelican import signals
+from pelican.contents import Content, Article
+
+
+def add_footer(content):
+    if not isinstance(content, Article):
+        return
+    
+    if 'FOOTER_INSERT_HTML' not in content.settings:
+        return
+    data_dict = {
+        'title': content.title,
+        'url': content.url,
+        'author': content.author.name,
+        'authors': ','.join([x.name for x in content.authors]),
+        'slug': content.slug,
+        'category': content.category,
+        'summary': content.summary,
+    }
+    if hasattr(content, 'date'):
+        data_dict['date'] = content.date
+    foot_insert_html = content.settings['FOOTER_INSERT_HTML'] % data_dict
+    content.footer_insert_html = foot_insert_html
+
+def register():
+    signals.content_object_init.connect(add_footer)