Browse Source

[pelican_comment_system] Increases interoperability with other plugins

     - The main logic starts now with the `article_generator_finalized` signal.
       This allows other plugins to access the comment information of the articles.
     - readme: Updates urls
     - use the active write to write feeds (Don't recreate the default one multiple times)
Bernhard Scheirle 9 years ago
parent
commit
fcfa22a87e
2 changed files with 23 additions and 13 deletions
  1. 4 4
      pelican_comment_system/Readme.md
  2. 19 9
      pelican_comment_system/pelican_comment_system.py

+ 4 - 4
pelican_comment_system/Readme.md

@@ -10,11 +10,11 @@ The comments are stored in files which can be processed by Pelican (e.g.: Markdo
  - Easy styleable via the themes
 
 
-See it in action here: [blog.scheirle.de](http://blog.scheirle.de/posts/2014/March/29/static-comments-via-email/)
+See it in action here: [bernhard.scheirle.de](http://bernhard.scheirle.de/posts/2014/March/29/static-comments-via-email/)
 
-Author             | Website                   | Github
--------------------|---------------------------|------------------------------
-Bernhard Scheirle  | <http://blog.scheirle.de> | <https://github.com/Scheirle>
+Author             | Website                       | Github
+-------------------|-------------------------------|------------------------------
+Bernhard Scheirle  | <http://bernhard.scheirle.de> | <https://github.com/Scheirle>
 
 ## Instructions
  - [Installation and basic usage](doc/installation.md)

+ 19 - 9
pelican_comment_system/pelican_comment_system.py

@@ -24,6 +24,7 @@ from . import avatars
 
 
 _all_comments = []
+pelican_writer = None
 
 def setdefault(pelican, settings):
     from pelican.settings import DEFAULT_CONFIG
@@ -57,11 +58,12 @@ def pelican_initialized(pelican):
         DEFAULT_CONFIG['PELICAN_COMMENT_SYSTEM_DIR'])
     DEFAULT_CONFIG['ARTICLE_EXCLUDES'].append(
         DEFAULT_CONFIG['PELICAN_COMMENT_SYSTEM_DIR'])
-    if pelican:
-        pelican.settings['PAGE_EXCLUDES'].append(
-            pelican.settings['PELICAN_COMMENT_SYSTEM_DIR'])
-        pelican.settings['ARTICLE_EXCLUDES'].append(
-            pelican.settings['PELICAN_COMMENT_SYSTEM_DIR'])
+    pelican.settings['PAGE_EXCLUDES'].append(
+        pelican.settings['PELICAN_COMMENT_SYSTEM_DIR'])
+    pelican.settings['ARTICLE_EXCLUDES'].append(
+        pelican.settings['PELICAN_COMMENT_SYSTEM_DIR'])
+    global pelican_writer
+    pelican_writer = pelican.get_writer()
 
 
 def initialize(article_generator):
@@ -111,7 +113,6 @@ def write_feed_all(gen, writer):
         com.title = com.article.title + " - " + com.title
         com.override_url = com.article.url + com.url
 
-    writer = Writer(gen.output_path, settings=gen.settings)
     writer.write_feed(_all_comments, context, path)
 
 
@@ -120,10 +121,17 @@ def write_feed(gen, items, context, slug):
         return
 
     path = gen.settings['PELICAN_COMMENT_SYSTEM_FEED'] % slug
+    pelican_writer.write_feed(items, context, path)
 
-    writer = Writer(gen.output_path, settings=gen.settings)
-    writer.write_feed(items, context, path)
 
+def process_comments(article_generator):
+    for article in article_generator.articles:
+        add_static_comments(article_generator, article)
+
+def mirror_to_translations(article):
+    for translation in article.translations:
+        translation.comments_count = article.comments_count
+        translation.comments = article.comments
 
 def add_static_comments(gen, content):
     if gen.settings['PELICAN_COMMENT_SYSTEM'] is not True:
@@ -133,6 +141,7 @@ def add_static_comments(gen, content):
 
     content.comments_count = 0
     content.comments = []
+    mirror_to_translations(content)
 
     # Modify the local context, so we get proper values for the feed
     context = copy.copy(gen.context)
@@ -191,6 +200,7 @@ def add_static_comments(gen, content):
 
     content.comments_count = len(comments) + count
     content.comments = comments
+    mirror_to_translations(content)
 
 
 def writeIdenticonsToDisk(gen, writer):
@@ -208,7 +218,7 @@ def pelican_finalized(pelican):
 def register():
     signals.initialized.connect(pelican_initialized)
     signals.article_generator_init.connect(initialize)
-    signals.article_generator_write_article.connect(add_static_comments)
+    signals.article_generator_finalized.connect(process_comments)
     signals.article_writer_finalized.connect(writeIdenticonsToDisk)
     signals.article_writer_finalized.connect(write_feed_all)
     signals.finalized.connect(pelican_finalized)