Browse Source

better_figures_and_images: handle missing files due to Unicode

Before, we got an unhelpful crash when a file can't be found due to a
Unicode character in the name:

ERROR: Could not process ./2014-12-24-incubator-final.md
'ascii' codec can't encode character u'\xc2' in position 67: ordinal not in range(128)

After:

ERROR: Could not process ./2014-12-24-incubator-final.md
[Errno 2] No such file or directory: u'/Users/dhalperi/Code/blog/content/images/2014-12-04-fall-incubator-\xc2Katsuyama.JPG'

Reference: https://github.com/getpelican/pelican-plugins/pull/381
Daniel Halperin 9 years ago
parent
commit
d5b95b33c4
1 changed files with 2 additions and 1 deletions
  1. 2 1
      better_figures_and_images/better_figures_and_images.py

+ 2 - 1
better_figures_and_images/better_figures_and_images.py

@@ -13,6 +13,7 @@ TODO: Need to add a test.py for this plugin.
 
 """
 
+from __future__ import unicode_literals
 from os import path, access, R_OK
 
 from pelican import signals
@@ -52,7 +53,7 @@ def content_object_init(instance):
 
                 logger.debug('Better Fig. src: %s', src)
                 if not (path.isfile(src) and access(src, R_OK)):
-                    logger.error('Better Fig. Error: image not found: {}'.format(src))
+                    logger.error('Better Fig. Error: image not found: %s', src)
 
                 # Open the source image and query dimensions; build style string
                 im = Image.open(src)