From 4a32b5b9019896a3259efd9cd396a188de0b9457 Mon Sep 17 00:00:00 2001 From: Grygoriy Fuchedzhy Date: Tue, 29 Nov 2011 14:48:56 +0200 Subject: [PATCH] thumbnails plugin: make resources under content directory instead of generating them in deploy directly, make all thumnails in single place(content/.thumbnails) for simple maintenance but keep original deploy path to preserve naming logic in generated site --- hyde/ext/plugins/images.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/hyde/ext/plugins/images.py b/hyde/ext/plugins/images.py index c6195bd..cfeca5e 100644 --- a/hyde/ext/plugins/images.py +++ b/hyde/ext/plugins/images.py @@ -189,10 +189,20 @@ class ImageThumbnailsPlugin(Plugin): """ Generate a thumbnail for the given image """ - # Prepare path - path = os.path.join(os.path.dirname(resource.get_relative_deploy_path()), - "%s%s" % (prefix, os.path.basename(resource.get_relative_deploy_path()))) - target = File(Folder(resource.site.config.deploy_root_path).child(path)) + name = os.path.basename(resource.get_relative_deploy_path()) + # don't make thumbnails for thumbnails + if name.startswith(prefix): + return + # Prepare path, make all thumnails in single place(content/.thumbnails) + # for simple maintenance but keep original deploy path to preserve + # naming logic in generated site + path = os.path.join(".thumbnails", + os.path.dirname(resource.get_relative_deploy_path()), + "%s%s" % (prefix, name)) + target = File(Folder(resource.site.config.content_root_path).child(path)) + res = self.site.content.add_resource(target) + res.set_relative_deploy_path(res.get_relative_deploy_path().replace('.thumbnails/', '', 1)) + target.parent.make() if os.path.exists(target.path) and os.path.getmtime(resource.path) <= os.path.getmtime(target.path): return