Repository: getnikola/nikola

Issue:
Sample metadata.yml for demo gallery crashes
```pytb
$ nikola init -qd n; cd n
$ <!> add another language
$ mv galleries/demo/metadata.sample.yml galleries/demo/metadata.yml
$ nikola build
Scanning posts........done!
.  render_galleries:output/ko/galleries/demo/index.html
TaskError - taskid:render_galleries:output/ko/galleries/demo/index.html
PythonAction Error
Traceback (most recent call last):
  File "/Users/kwpolska/virtualenvs/nikola/lib/python3.6/site-packages/doit/action.py", line 424, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/Users/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 682, in render_gallery_index
    photo_array.append(photo_info.pop(entry))
KeyError: 'tesla4_lg.jpg'

<stdout>:
```
RSS feed generation fails with 8.0.0b1
<!--
Before creating an issue:
* make sure you are using an up-to-date version of Nikola
* search for existing issues that might be related

If you are reporting a bug:
* provide information about your environment (below)
* include all the output you get, and any other information related to your problem

Nikola v7.6.4, as provided by Ubuntu, is NOT SUPPORTED.
If you are using this version, you should upgrade: https://getnikola.com/getting-started.html
-->

### Environment (if reporting a bug)

**Python Version:** 3.5

**Nikola Version:** 8.0.0b1

**Operating System:** Solaris 11.4

### Description:

Kicking the tires with 8.0.0b1 ,I used the default conf.py which includes `GENERATE_RSS = True`.
While running `nikola build` the process died at the end of the gallery generation process:

```
[elided]
[2018-05-08T07:50:08Z] DEBUG: MARKDOWN: Successfully loaded extension "markdown.extensions.extra.ExtraExtension".
Scanning posts........done!
[2018-05-08T07:50:09Z] DEBUG: render_galleries: Using galleries/home/new_pool/metadata.yml for gallery galleries/home/new_pool
[2018-05-08T07:50:09Z] DEBUG: render_galleries: Using galleries/cycling/2018-02-18-coottha-yay/metadata.yml for gallery galleries/cycling/2018-02-18-coottha-yay
[2018-05-08T07:50:09Z] DEBUG: render_galleries: Using galleries/tourism/hmas_parramatta/metadata.yml for gallery galleries/tourism/hmas_parramatta
.  render_galleries:output/galleries/home/new_pool/index.html
.  render_galleries:output/galleries/cycling/2018-02-18-coottha-yay/rss.xml
TaskError - taskid:render_galleries:output/galleries/cycling/2018-02-18-coottha-yay/rss.xml
PythonAction Error
Traceback (most recent call last):
  File "/space/builds/jmcp/web/nikola/v-3.5/lib/python3.5/site-packages/doit/action.py", line 424, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/space/builds/jmcp/web/nikola/v-3.5/lib/python3.5/site-packages/nikola/plugins/task/galleries.py", line 736, in gallery_rss
    items.append(rss.RSSItem(**args))
  File "/space/builds/jmcp/web/nikola/v-3.5/lib/python3.5/site-packages/PyRSS2Gen.py", line 410, in __init__
    "must define at least one of 'title' or 'description'")
TypeError: must define at least one of 'title' or 'description'

########################################
render_galleries:output/galleries/cycling/2018-02-18-coottha-yay/rss.xml <stdout>:

```






un-captioned images in metadata.yml
<!--
Before creating an issue:
* make sure you are using an up-to-date version of Nikola
* search for existing issues that might be related

If you are reporting a bug:
* provide information about your environment (below)
* include all the output you get, and any other information related to your problem

Nikola v7.6.4, as provided by Ubuntu, is NOT SUPPORTED.
If you are using this version, you should upgrade: https://getnikola.com/getting-started.html
-->

### Environment (if reporting a bug)

**Python Version:** 3.5

**Nikola Version:** 8.0.0b1

**Operating System:**  Solaris 11.4

### Description:

 I have a test metadata.yml which does not have captions for all images in a specific gallery. I noticed with the 8.0.0b1 build that the images without captions have "None" printed for the caption when viewing the gallery. 
RSS feed generation fails with 8.0.0b1
<!--
Before creating an issue:
* make sure you are using an up-to-date version of Nikola
* search for existing issues that might be related

If you are reporting a bug:
* provide information about your environment (below)
* include all the output you get, and any other information related to your problem

Nikola v7.6.4, as provided by Ubuntu, is NOT SUPPORTED.
If you are using this version, you should upgrade: https://getnikola.com/getting-started.html
-->

### Environment (if reporting a bug)

**Python Version:** 3.5

**Nikola Version:** 8.0.0b1

**Operating System:** Solaris 11.4

### Description:

Kicking the tires with 8.0.0b1 ,I used the default conf.py which includes `GENERATE_RSS = True`.
While running `nikola build` the process died at the end of the gallery generation process:

```
[elided]
[2018-05-08T07:50:08Z] DEBUG: MARKDOWN: Successfully loaded extension "markdown.extensions.extra.ExtraExtension".
Scanning posts........done!
[2018-05-08T07:50:09Z] DEBUG: render_galleries: Using galleries/home/new_pool/metadata.yml for gallery galleries/home/new_pool
[2018-05-08T07:50:09Z] DEBUG: render_galleries: Using galleries/cycling/2018-02-18-coottha-yay/metadata.yml for gallery galleries/cycling/2018-02-18-coottha-yay
[2018-05-08T07:50:09Z] DEBUG: render_galleries: Using galleries/tourism/hmas_parramatta/metadata.yml for gallery galleries/tourism/hmas_parramatta
.  render_galleries:output/galleries/home/new_pool/index.html
.  render_galleries:output/galleries/cycling/2018-02-18-coottha-yay/rss.xml
TaskError - taskid:render_galleries:output/galleries/cycling/2018-02-18-coottha-yay/rss.xml
PythonAction Error
Traceback (most recent call last):
  File "/space/builds/jmcp/web/nikola/v-3.5/lib/python3.5/site-packages/doit/action.py", line 424, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/space/builds/jmcp/web/nikola/v-3.5/lib/python3.5/site-packages/nikola/plugins/task/galleries.py", line 736, in gallery_rss
    items.append(rss.RSSItem(**args))
  File "/space/builds/jmcp/web/nikola/v-3.5/lib/python3.5/site-packages/PyRSS2Gen.py", line 410, in __init__
    "must define at least one of 'title' or 'description'")
TypeError: must define at least one of 'title' or 'description'

########################################
render_galleries:output/galleries/cycling/2018-02-18-coottha-yay/rss.xml <stdout>:

```








Discussion:

I tried creating an index.txt which contained both a title and description in reST, but there was no difference to the error from the rss generator

I hacked up this fix:

```
$ git diff
diff --git a/nikola/plugins/task/galleries.py b/nikola/plugins/task/galleries.py
index dd969d26..6b34313f 100644
--- a/nikola/plugins/task/galleries.py
+++ b/nikola/plugins/task/galleries.py
@@ -465,6 +465,8 @@ class Galleries(Task, ImageProcessor):
                     img_name = img.pop('name')
                     if 'caption' in img:
                         captions[img_name] = img.pop('caption')
+                    else:
+                        captions[img_name] = ""
 
                     if 'order' in img:
                         order.insert(img.pop('order'), img_name)
```

I tried creating an index.txt which contained both a title and description in reST, but there was no difference to the error from the rss generator


Resolving patch:
diff --git a/nikola/plugins/task/galleries.py b/nikola/plugins/task/galleries.py
--- a/nikola/plugins/task/galleries.py
+++ b/nikola/plugins/task/galleries.py
@@ -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']))
@@ -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)
@@ -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': {
@@ -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']:


Test patch: