« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/misc-templates.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/misc-templates.js b/src/misc-templates.js
index e8c7496c..aa21a390 100644
--- a/src/misc-templates.js
+++ b/src/misc-templates.js
@@ -654,18 +654,27 @@ function unbound_img({
   lazy = false,
   square = false,
 }) {
-  let fileSize = null;
-  const mediaRoot = to('media.root');
-  if (src.startsWith(mediaRoot)) {
-    fileSize = getSizeOfImageFile(src.slice(mediaRoot.length).replace(/^\//, ''));
-  }
-
   const willSquare = square;
   const willLink = typeof link === 'string' || link;
 
   const originalSrc = src;
   const thumbSrc = src && (thumbKey ? thumb[thumbKey](src) : src);
 
+  const href =
+    (willLink
+      ? (typeof link === 'string'
+          ? link
+          : originalSrc)
+      : null);
+
+  let fileSize = null;
+  const mediaRoot = to('media.root');
+  if (href?.startsWith(mediaRoot)) {
+    console.log(href.slice(mediaRoot.length).replace(/^\//, ''));
+    console.log(getSizeOfImageFile(href.slice(mediaRoot.length).replace(/^\//, '')));
+    fileSize = getSizeOfImageFile(href.slice(mediaRoot.length).replace(/^\//, ''));
+  }
+
   const imgAttributes = {
     id: link ? '' : id,
     class: className,
@@ -734,7 +743,7 @@ function unbound_img({
         {
           id,
           class: ['box', hide && 'js-hide', 'image-link'],
-          href: typeof link === 'string' ? link : originalSrc,
+          href,
         },
         wrapped);
     }