Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* `Aru Sahni <https://github.com/arusahni>`_
* `Arun Persaud <https://github.com/arunpersaud>`_
* `Aurelien Naldi <https://github.com/aurelien-naldi>`_
* `Ayudh Haldar <https://github.com/Ayudh-M>`_
* `Ben Mather <https://github.com/bwhmather>`_
* `Bendik Knapstad <https://github.com/knapstad>`_
* `Boris Kaul <https://github.com/localvoid>`_
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Features
Bugfixes
--------

* Ignore “`sizes` ⇒ false” in WordPress attachment metadata to prevent a crash in ``import_wordpress`` (Issue #3810)
* Ignore errors in parsing SVG files for shrinking them, copy original file to output instead
(Issue #3785)
* Restore ``annotation_helper.tmpl`` with dummy content - fix themes still mentioning it
Expand All @@ -47,6 +48,7 @@ Bugfixes
* ``nikola serve`` now works with non-root SITE_URL.
* Stack traces meaningless for end users now more reliably suppressed (Issue #3838).


Other
-----

Expand Down
48 changes: 37 additions & 11 deletions nikola/plugins/command/import_wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,21 +626,47 @@ def add(our_key, wp_key, is_int=False, ignore_zero=False, is_float=False):
if len(dst_meta) > 0:
files_meta[0]['meta'] = dst_meta

# ------------------------------------------------------------------
# Previous implementation kept only for reference:
# Find other sizes of image
if size_key not in metadata:
continue
# if size_key not in metadata:
# continue

for size in metadata[size_key]:
filename = metadata[size_key][size][file_key]
url = '/'.join([source_path, filename.decode('utf-8')])
# for size in metadata[size_key]:
# filename = metadata[size_key][size][file_key]
# url = '/'.join([source_path, filename.decode('utf-8')])

# Construct metadata
meta = {}
meta['size'] = size.decode('utf-8')
if width_key in metadata[size_key][size] and height_key in metadata[size_key][size]:
meta['width'] = int(metadata[size_key][size][width_key])
meta['height'] = int(metadata[size_key][size][height_key])
# # Construct metadata
# meta = {}
# meta['size'] = size.decode('utf-8')
# if width_key in metadata[size_key][size] and height_key in metadata[size_key][size]:
# meta['width'] = int(metadata[size_key][size][width_key])
# meta['height'] = int(metadata[size_key][size][height_key])
# ------------------------------------------------------------------

# Find other sizes of image — *robust to `"sizes" => false`*
sizes_dict = metadata.get(size_key)

# WP ≥ 6 writes `"sizes" => false` when no thumbnails exist.
# That becomes Python `False`, which is not iterable/subscriptable
# and caused TypeError: 'bool' object is not subscriptable (#3810).
if not isinstance(sizes_dict, dict):
continue # nothing more to import for this element

for size, size_info in sizes_dict.items():
if not isinstance(size_info, dict) or file_key not in size_info:
continue # skip malformed entries

filename = size_info[file_key]
url = "/".join([source_path, filename.decode("utf-8")])

# Construct metadata
meta = {"size": size.decode("utf-8")}
if width_key in size_info and height_key in size_info:
meta["width"] = int(size_info[width_key])
meta["height"] = int(size_info[height_key])
# ------------------------------------------------------------------

path = urlparse(url).path
dst_path = os.path.join(*([self.output_folder, 'files'] + list(path.split('/'))))
if self.no_downloads:
Expand Down
Loading