Browse Source

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

main
Grygoriy Fuchedzhy 13 years ago
committed by Lakshmi Vyasarajan
parent
commit
4a32b5b901
1 changed files with 14 additions and 4 deletions
  1. +14
    -4
      hyde/ext/plugins/images.py

+ 14
- 4
hyde/ext/plugins/images.py View File

@@ -189,10 +189,20 @@ class ImageThumbnailsPlugin(Plugin):
""" """
Generate a thumbnail for the given image 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() target.parent.make()
if os.path.exists(target.path) and os.path.getmtime(resource.path) <= os.path.getmtime(target.path): if os.path.exists(target.path) and os.path.getmtime(resource.path) <= os.path.getmtime(target.path):
return return


Loading…
Cancel
Save