« get me outta code hell

content: image: custom-handle images assessed to be missing - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-11 15:11:24 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-11 15:11:24 -0300
commita88d346f9e7c2c9b01795c10761a5ec698e88f94 (patch)
tree2b7ec832a33e06caa0320bbba4a402bdac585454
parentb19e165dc8ba13cd0e2d1862e645d34d86142566 (diff)
content: image: custom-handle images assessed to be missing
-rw-r--r--src/content/dependencies/image.js42
-rw-r--r--src/strings-default.json1
2 files changed, 30 insertions, 13 deletions
diff --git a/src/content/dependencies/image.js b/src/content/dependencies/image.js
index b5591e6..64fe853 100644
--- a/src/content/dependencies/image.js
+++ b/src/content/dependencies/image.js
@@ -1,4 +1,4 @@
-import {logWarn} from '#cli';
+import {logInfo, logWarn} from '#cli';
 import {empty} from '#sugar';
 
 export default {
@@ -10,6 +10,7 @@ export default {
     'getThumbnailsAvailableForDimensions',
     'html',
     'language',
+    'missingImagePaths',
     'to',
   ],
 
@@ -63,6 +64,7 @@ export default {
     getThumbnailsAvailableForDimensions,
     html,
     language,
+    missingImagePaths,
     to,
   }) {
     let originalSrc;
@@ -75,8 +77,27 @@ export default {
       originalSrc = '';
     }
 
-    const willLink = typeof slots.link === 'string' || slots.link;
-    const customLink = typeof slots.link === 'string';
+    let mediaSrc = null;
+    if (originalSrc.startsWith(to('media.root'))) {
+      mediaSrc =
+        originalSrc
+          .slice(to('media.root').length)
+          .replace(/^\//, '');
+    }
+
+    const isMissingImageFile =
+      missingImagePaths.includes(mediaSrc);
+
+    if (isMissingImageFile) {
+      logInfo`No image file for ${mediaSrc} - build again for list of missing images.`;
+    }
+
+    const willLink =
+      !isMissingImageFile &&
+      (typeof slots.link === 'string' || slots.link);
+
+    const customLink =
+      typeof slots.link === 'string';
 
     const willReveal =
       slots.reveal &&
@@ -87,13 +108,16 @@ export default {
 
     const idOnImg = willLink ? null : slots.id;
     const idOnLink = willLink ? slots.id : null;
+
     const classOnImg = willLink ? null : slots.class;
     const classOnLink = willLink ? slots.class : null;
 
-    if (!originalSrc) {
+    if (!originalSrc || isMissingImageFile) {
       return prepare(
         html.tag('div', {class: 'image-text-area'},
-          slots.missingSourceContent));
+          (html.isBlank(slots.missingSourceContent)
+            ? language.$(`misc.missingImage`)
+            : slots.missingSourceContent)));
     }
 
     let reveal = null;
@@ -108,14 +132,6 @@ export default {
       ];
     }
 
-    let mediaSrc = null;
-    if (originalSrc.startsWith(to('media.root'))) {
-      mediaSrc =
-        originalSrc
-          .slice(to('media.root').length)
-          .replace(/^\//, '');
-    }
-
     const hasThumbnails =
       mediaSrc &&
       checkIfImagePathHasCachedThumbnails(mediaSrc);
diff --git a/src/strings-default.json b/src/strings-default.json
index 8d7756a..b5e39e9 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -197,6 +197,7 @@
   "misc.external.flash.homestuck.page": "{LINK} (page {PAGE})",
   "misc.external.flash.homestuck.secret": "{LINK} (secret page)",
   "misc.external.flash.youtube": "{LINK} (on any device)",
+  "misc.missingImage": "(This image file is missing)",
   "misc.missingLinkContent": "(Missing link content)",
   "misc.nav.previous": "Previous",
   "misc.nav.next": "Next",