Pārlūkot izejas kodu

Merge pull request #782 from Scheirle/pcs_autoreload

[pelican_comment_system] Add support for the autoreload mode of pelican
Justin Mayer 8 gadi atpakaļ
vecāks
revīzija
400bbf1a8b

+ 46 - 0
pelican_comment_system/CHANGELOG.md

@@ -0,0 +1,46 @@
+# Change Log #
+All notable changes to this project will be documented in this file.
+This project adheres to [Semantic Versioning](http://semver.org/).
+
+## x.x.x – TBA
+### Fixed
+- Add support for the autoreload mode of pelican [PR #782](https://github.com/getpelican/pelican-plugins/pull/782) [Fixes pelican#1949](https://github.com/getpelican/pelican/issues/1949)
+
+## 1.2.0 – 2016-05-23
+### Fixed - Documentation
+- Correct template path [PR #713](https://github.com/getpelican/pelican-plugins/pull/713)
+
+### Added - Documentation
+- Adds Quickstart guide + default theme [PR #686](https://github.com/getpelican/pelican-plugins/pull/686)
+
+### Fixed
+- Fix mailto link: use '\r\n' instead of '\n' [PR #720](https://github.com/getpelican/pelican-plugins/pull/720)
+- Fix comparison of offset-naive and offset-aware datetimes [PR #722](https://github.com/getpelican/pelican-plugins/pull/722)
+
+### Added
+- Logs a warning if the parent of a comment can not be found [PR #715](https://github.com/getpelican/pelican-plugins/pull/715)
+
+## 1.1.0 – 2016-02-18
+### Fixed – Documentation
+- Updated old URLs [PR #677](https://github.com/getpelican/pelican-plugins/pull/677)
+
+### Changed
+- Main logic runs a bit earlier (allows other plugins to access comments earlier)  [PR #677](https://github.com/getpelican/pelican-plugins/pull/677)
+- The writer to generate the feeds can now be exchanged (via a normal pelican writer plugin) [PR #677](https://github.com/getpelican/pelican-plugins/pull/677)
+
+
+## 1.0.1 – 2015-10-04
+### Fixed – Documentation
+- Add commas indicating tuple (`PELICAN_COMMENT_SYSTEM_AUTHORS`) [PR #579](https://github.com/getpelican/pelican-plugins/pull/579)
+
+
+## 1.0.0 – 2014-11-05
+### Added
+- Basic static comments
+- Atom Feeds
+- Replies to comments
+- Avatars and identicons
+
+
+This change log uses [Keep a CHANGELOG](http://keepachangelog.com/) as a template.
+

+ 5 - 0
pelican_comment_system/Readme.md

@@ -11,6 +11,7 @@ Comments are stored in files in formats that can be processed by Pelican (e.g.,
  - Avatars and [Identicons](https://en.wikipedia.org/wiki/Identicon)
  - Comment Atom feed for each article
  - Easy styleable via themes
+ - Python 2 and 3 support
 
 
 See it in action here: [bernhard.scheirle.de](http://bernhard.scheirle.de/posts/2014/March/29/static-comments-via-email/)
@@ -37,3 +38,7 @@ To create identicons, the Python Image Library is needed. Therefore you either n
     pip install Pillow
 
 If you don't want avatars or identicons, this plugin works fine without PIL/Pillow. You will, however, see a warning that identicons are deactivated (as expected).
+
+## Change Log
+
+The change log can be found in the [CHANGELOG.md](./CHANGELOG.md) file.

+ 5 - 2
pelican_comment_system/avatars.py

@@ -46,14 +46,15 @@ def init(pelican_output_path, identicon_output_path, identicon_data,
     global _identicon_size
     global _initialized
     global _authors
-    if _initialized:
-        return
+    global _missingAvatars
+
     _identicon_save_path = os.path.join(pelican_output_path,
                                         identicon_output_path)
     _identicon_output_path = identicon_output_path
     _identicon_data = identicon_data
     _identicon_size = identicon_size
     _authors = authors
+    _missingAvatars = []
     _initialized = True
 
 
@@ -95,8 +96,10 @@ def getAvatarPath(comment_id, metadata):
 
 def generateAndSaveMissingAvatars():
     _createIdenticonOutputFolder()
+    global _missingAvatars
     for code in _missingAvatars:
         avatar_path = '%s.png' % code
         avatar = identicon.render_identicon(int(code, 16), _identicon_size)
         avatar_save_path = os.path.join(_identicon_save_path, avatar_path)
         avatar.save(avatar_save_path, 'PNG')
+    _missingAvatars = []

+ 11 - 5
pelican_comment_system/pelican_comment_system.py

@@ -24,7 +24,8 @@ from . import avatars
 
 
 _all_comments = []
-pelican_writer = None
+_pelican_writer = None
+_pelican_obj = None
 
 def setdefault(pelican, settings):
     from pelican.settings import DEFAULT_CONFIG
@@ -62,8 +63,9 @@ def pelican_initialized(pelican):
         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()
+
+    global _pelican_obj
+    _pelican_obj = pelican
 
 
 def initialize(article_generator):
@@ -77,6 +79,11 @@ def initialize(article_generator):
         article_generator.settings['PELICAN_COMMENT_SYSTEM_AUTHORS'],
     )
 
+    # Reset old states (autoreload mode)
+    global _all_comments
+    global _pelican_writer
+    _pelican_writer = _pelican_obj.get_writer()
+    _all_comments = []
 
 def warn_on_slug_collision(items):
     slugs = {}
@@ -121,7 +128,7 @@ def write_feed(gen, items, context, slug):
         return
 
     path = gen.settings['PELICAN_COMMENT_SYSTEM_FEED'] % slug
-    pelican_writer.write_feed(items, context, path)
+    _pelican_writer.write_feed(items, context, path)
 
 
 def process_comments(article_generator):
@@ -219,7 +226,6 @@ def pelican_finalized(pelican):
         return
     global _all_comments
     print('Processed %s comment(s)' % len(_all_comments))
-    _all_comments = []
 
 
 def register():