Skip to content

Commit

Permalink
Fix exception from gallery RSS with WebP images
Browse files Browse the repository at this point in the history
WebP images in a gallery cause `nikola build` to fail with an unhandled
AttributeError exception, as described in getnikola#3671.

This happens because the MIME type of WebP images is not known, and the
resulting None value causes the RSS generation code to choke.

This PR fixes that, by augmenting Python's list of known mimetypes with
a hardcoded WebP one, before we ask for the mimetype of each image in a
gallery.

This addresses the above issue's checklist item "*Inject a hardcoded
'image/web' mimetype at runtime, before .guess_type() gets called.*",
but does not complete the issue.
  • Loading branch information
tartley committed Mar 26, 2023
1 parent 483ffd8 commit 4a8f1bf
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nikola/data/samplesite/galleries/demo/metadata.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ order: 2
name: tesla4_lg.jpg
order: 0
---
name: tesla_conducts_lg.jpg
name: tesla_conducts_lg.webp
caption: Nikola Tesla conducts electricity
order: 1
---
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions nikola/plugins/task/galleries.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ def gallery_rss(self, img_list, dest_img_list, img_titles, lang, permalink, outp
def make_url(url):
return urljoin(self.site.config['BASE_URL'], url.lstrip('/'))

# WebP is not yet an official MIME type but we need to recognize them
mimetypes.add_type('image/webp', '.webp')

all_data = list(zip(img_list, dest_img_list, img_titles))

if self.kw['sort_by_date']:
Expand Down

0 comments on commit 4a8f1bf

Please sign in to comment.