Skip to content

Commit

Permalink
Merge pull request #3079 from getnikola/gallery-meta-fixes
Browse files Browse the repository at this point in the history
Assorted gallery metadata fixes (#3076 #3077 #3078)
  • Loading branch information
Kwpolska committed May 8, 2018
2 parents 9d3be97 + 0a34425 commit daa0cd0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Features
Bugfixes
--------

* Guard against null items in gallery meta files (Issues #3076, #3077)
* Respect ``USE_FILENAME_AS_TITLE`` in galleries with a meta file
* Fix gallery metadata for multilingual sites (Issue #3078)

New in v8.0.0b1
===============

Expand Down
22 changes: 13 additions & 9 deletions nikola/plugins/task/galleries.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ def gen_tasks(self):
if fn in captions:
img_titles.append(captions[fn])
else:
img_titles.append(fn)
if self.kw['use_filename_as_title']:
img_titles.append(fn)
else:
img_titles.append('')
self.logger.debug(
"Image {0} found in gallery but not listed in {1}".
format(fn, context['meta_path']))
Expand Down Expand Up @@ -463,10 +466,10 @@ def find_metadata(self, gallery, lang):
continue
if 'name' in img:
img_name = img.pop('name')
if 'caption' in img:
if 'caption' in img and img['caption']:
captions[img_name] = img.pop('caption')

if 'order' in img:
if 'order' in img and img['order'] is not None:
order.insert(img.pop('order'), img_name)
else:
order.append(img_name)
Expand Down Expand Up @@ -661,10 +664,11 @@ def url_from_path(p):
im = Image.open(thumb)
w, h = im.size
_image_size_cache[thumb] = w, h
# Thumbs are files in output, we need URLs
url = url_from_path(img)
photo_info[url] = {
'url': url,
# Use basename to avoid issues with multilingual sites (Issue #3078)
img_basename = os.path.basename(img)
photo_info[img_basename] = {
# Thumbs are files in output, we need URLs
'url': url_from_path(img),
'url_thumb': url_from_path(thumb),
'title': title,
'size': {
Expand All @@ -674,8 +678,8 @@ def url_from_path(p):
'width': w,
'height': h
}
if url in img_metadata:
photo_info[url].update(img_metadata[url])
if img_basename in img_metadata:
photo_info[img_basename].update(img_metadata[img_basename])
photo_array = []
if context['order']:
for entry in context['order']:
Expand Down

0 comments on commit daa0cd0

Please sign in to comment.