From 2d1a7eceb04376b277adb5b6d1530aa30d6e7a61 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Wed, 21 Aug 2019 19:47:49 +0200 Subject: [PATCH] "item is null" Tentatively fixes #1 --- scripts/gather.ts | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/scripts/gather.ts b/scripts/gather.ts index ae15a3d..952f38f 100644 --- a/scripts/gather.ts +++ b/scripts/gather.ts @@ -109,25 +109,34 @@ class Gatherer { } *collectImagesInternal(img: HTMLImageElement) { - const src = img.currentSrc || img.src; - const item = this.makeItem(src, img); - item.fileName = ""; - item.description = item.title; - yield item; - - const {srcset} = img; - if (!srcset) { - return; - } - const imgs = srcset.split(",").flatMap(e => { - const idx = e.lastIndexOf(" "); - return (idx > 0 ? e.slice(0, idx) : e).trim(); - }); - for (const i of imgs) { - const item = this.makeItem(i, img); + try { + const src = img.currentSrc || img.src; + const item = this.makeItem(src, img); if (item) { + item.fileName = ""; + item.description = item.title; yield item; } + + const {srcset} = img; + if (!srcset) { + return; + } + const imgs = srcset.split(",").flatMap(e => { + const idx = e.lastIndexOf(" "); + return (idx > 0 ? e.slice(0, idx) : e).trim(); + }); + for (const i of imgs) { + const item = this.makeItem(i, img); + if (item) { + item.fileName = ""; + item.description = item.title; + yield item; + } + } + } + catch (ex) { + console.error("oops image", ex.toString(), ex.stack, ex); } }