Pārlūkot izejas kodu

Added option to save the file tree in the generation of thumbnailes.

Ivan Kravchenko 9 gadi atpakaļ
vecāks
revīzija
66e29469c3
2 mainītis faili ar 7 papildinājumiem un 1 dzēšanām
  1. 1 0
      thumbnailer/Readme.md
  2. 6 1
      thumbnailer/thumbnailer.py

+ 1 - 0
thumbnailer/Readme.md

@@ -22,6 +22,7 @@ Configuration
 * `THUMBNAIL_SIZES` is a dictionary mapping name of size to size specifications.
   The generated filename will be `originalname_thumbnailname.ext` unless `THUMBNAIL_KEEP_NAME` is set.
 * `THUMBNAIL_KEEP_NAME` is a boolean which if set puts the file with the original name in a thumbnailname folder, named like the key in `THUMBNAIL_SIZES`.
+* `THUMBNAIL_KEEP_TREE` is a boolean flag to save image directory tree.
 
 Sizes can be specified using any of the following formats:
 

+ 6 - 1
thumbnailer/thumbnailer.py

@@ -144,7 +144,12 @@ def resize_thumbnails(pelican):
                     in_filename = path.join(dirpath, filename)
                     logger.debug("Processing thumbnail {0}=>{1}".format(filename, name))
                     if pelican.settings.get('THUMBNAIL_KEEP_NAME', False):
-                        resizer.resize_file_to(in_filename, path.join(out_path, name), True)
+                        if pelican.settings.get('THUMBNAIL_KEEP_TREE', False):
+                            resizer.resize_file_to(
+                                in_filename, 
+                                path.join(out_path, name, path.dirname(path.relpath(in_filename, in_path))), True)
+                        else:
+                            resizer.resize_file_to(in_filename, path.join(out_path, name), True)
                     else:
                         resizer.resize_file_to(in_filename, out_path)