summaryrefslogtreecommitdiffstats
path: root/nikola/plugins/task_render_galleries.py
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/plugins/task_render_galleries.py')
-rw-r--r--nikola/plugins/task_render_galleries.py53
1 files changed, 31 insertions, 22 deletions
diff --git a/nikola/plugins/task_render_galleries.py b/nikola/plugins/task_render_galleries.py
index 72d0581..7fe1501 100644
--- a/nikola/plugins/task_render_galleries.py
+++ b/nikola/plugins/task_render_galleries.py
@@ -26,8 +26,8 @@ from __future__ import unicode_literals
import codecs
import datetime
import glob
+import hashlib
import os
-import uuid
Image = None
try:
@@ -76,7 +76,7 @@ class Galleries(Task):
yield {
'basename': str('render_galleries'),
'actions': [],
- }
+ }
return
# gallery_path is "gallery/name"
@@ -88,8 +88,9 @@ class Galleries(Task):
else:
gallery_name = os.path.join(*splitted)
# output_gallery is "output/GALLERY_PATH/name"
- output_gallery = os.path.dirname(os.path.join(kw["output_folder"],
- self.site.path("gallery", gallery_name, None)))
+ output_gallery = os.path.dirname(os.path.join(
+ kw["output_folder"], self.site.path("gallery", gallery_name,
+ None)))
if not os.path.isdir(output_gallery):
yield {
'basename': str('render_galleries'),
@@ -98,7 +99,7 @@ class Galleries(Task):
'targets': [output_gallery],
'clean': True,
'uptodate': [utils.config_changed(kw)],
- }
+ }
# image_list contains "gallery/name/image_name.jpg"
image_list = glob.glob(gallery_path + "/*jpg") +\
glob.glob(gallery_path + "/*JPG") +\
@@ -118,21 +119,21 @@ class Galleries(Task):
excluded_image_name_list = []
excluded_image_list = list(map(add_gallery_path,
- excluded_image_name_list))
+ excluded_image_name_list))
image_set = set(image_list) - set(excluded_image_list)
image_list = list(image_set)
except IOError:
pass
# List of sub-galleries
- folder_list = [x.split(os.sep)[-2] for x in
- glob.glob(os.path.join(gallery_path, '*') + os.sep)]
+ folder_list = [x.split(os.sep)[-2] + os.sep for x in
+ glob.glob(os.path.join(gallery_path, '*') + os.sep)]
crumbs = gallery_path.split(os.sep)[:-1]
crumbs.append(os.path.basename(gallery_name))
# TODO: write this in human
paths = ['/'.join(['..'] * (len(crumbs) - 1 - i)) for i in
- range(len(crumbs[:-1]))] + ['#']
+ range(len(crumbs[:-1]))] + ['#']
crumbs = list(zip(paths, crumbs))
image_list = [x for x in image_list if "thumbnail" not in x]
@@ -150,7 +151,7 @@ class Galleries(Task):
# thumb_path is
# "output/GALLERY_PATH/name/image_name.thumbnail.jpg"
thumb_path = os.path.join(output_gallery,
- fname + ".thumbnail" + ext)
+ ".thumbnail".join([fname, ext]))
# thumb_path is "output/GALLERY_PATH/name/image_name.jpg"
orig_dest_path = os.path.join(output_gallery, img_name)
thumbs.append(os.path.basename(thumb_path))
@@ -182,12 +183,12 @@ class Galleries(Task):
# Remove excluded images
if excluded_image_name_list:
for img, img_name in zip(excluded_image_list,
- excluded_image_name_list):
+ excluded_image_name_list):
# img_name is "image_name.jpg"
# fname, ext are "image_name", ".jpg"
fname, ext = os.path.splitext(img_name)
- excluded_thumb_dest_path = os.path.join(output_gallery,
- fname + ".thumbnail" + ext)
+ excluded_thumb_dest_path = os.path.join(
+ output_gallery, ".thumbnail".join([fname, ext]))
excluded_dest_path = os.path.join(output_gallery, img_name)
yield {
'basename': str('render_galleries'),
@@ -218,7 +219,8 @@ class Galleries(Task):
context["title"] = os.path.basename(gallery_path)
context["description"] = kw["blog_description"]
if kw['use_filename_as_title']:
- img_titles = ['id="%s" alt="%s" title="%s"' % (fn[:-4], fn[:-4], utils.unslugify(fn[:-4]))
+ img_titles = ['id="%s" alt="%s" title="%s"' %
+ (fn[:-4], fn[:-4], utils.unslugify(fn[:-4]))
for fn in image_name_list]
else:
img_titles = [''] * len(image_name_list)
@@ -227,14 +229,19 @@ class Galleries(Task):
context["crumbs"] = crumbs
context["permalink"] = self.site.link(
"gallery", gallery_name, None)
+ context["enable_comments"] = (
+ self.site.config["COMMENTS_IN_GALLERIES"])
# Use galleries/name/index.txt to generate a blurb for
# the gallery, if it exists
index_path = os.path.join(gallery_path, "index.txt")
cache_dir = os.path.join(kw["cache_folder"], 'galleries')
if not os.path.isdir(cache_dir):
- os.makedirs(cache_dir)
- index_dst_path = os.path.join(cache_dir, str(uuid.uuid1())+'.html')
+ os.makedirs(cache_dir)
+ index_dst_path = os.path.join(
+ cache_dir,
+ str(hashlib.sha224(index_path.encode('utf-8')).hexdigest() +
+ '.html'))
if os.path.exists(index_path):
compile_html = self.site.get_compiler(index_path)
yield {
@@ -242,8 +249,7 @@ class Galleries(Task):
'name': index_dst_path.encode('utf-8'),
'file_dep': [index_path],
'targets': [index_dst_path],
- 'actions': [(compile_html,
- [index_path, index_dst_path])],
+ 'actions': [(compile_html, [index_path, index_dst_path])],
'clean': True,
'uptodate': [utils.config_changed(kw)],
}
@@ -258,19 +264,22 @@ class Galleries(Task):
file_dep.append(index_dst_path)
else:
context['text'] = ''
- self.site.render_template(template_name, output_name, context)
+ self.site.render_template(template_name, output_name.encode(
+ 'utf8'), context)
yield {
'basename': str('render_galleries'),
'name': output_name.encode('utf8'),
'file_dep': file_dep,
'targets': [output_name],
- 'actions': [(render_gallery,
- (output_name, context, index_dst_path))],
+ 'actions': [(render_gallery, (output_name, context,
+ index_dst_path))],
'clean': True,
'uptodate': [utils.config_changed({
1: kw,
- 2: self.site.config['GLOBAL_CONTEXT']})],
+ 2: self.site.config['GLOBAL_CONTEXT'],
+ 3: self.site.config["COMMENTS_IN_GALLERIES"],
+ })],
}
def resize_image(self, src, dst, max_size):