« get me outta code hell

data, content: Artwork.path - 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>2025-04-02 18:41:13 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-04-10 16:02:38 -0300
commitb99aaacf875b826bc196d992412a0bf246bd4f9b (patch)
treeb5cbba7297a128cb82d3d0cbac14a8fdb756dd29
parent58fba5a7a859c5398e0e58f31d7e8e5a649db63b (diff)
data, content: Artwork.path
Lots of cleanup for generateCoverArtwork now that it's in charge
of its own image (again, apparently)

Still broken for anything besides tracks
-rw-r--r--src/content/dependencies/generateCoverArtwork.js53
-rw-r--r--src/content/dependencies/generateTrackCoverArtwork.js23
-rw-r--r--src/data/things/album.js8
-rw-r--r--src/data/things/artwork.js7
-rw-r--r--src/data/things/track.js11
5 files changed, 62 insertions, 40 deletions
diff --git a/src/content/dependencies/generateCoverArtwork.js b/src/content/dependencies/generateCoverArtwork.js
index 719d14e9..8b5f9b8e 100644
--- a/src/content/dependencies/generateCoverArtwork.js
+++ b/src/content/dependencies/generateCoverArtwork.js
@@ -9,6 +9,9 @@ export default {
   extraDependencies: ['html'],
 
   relations: (relation, artwork) => ({
+    image:
+      relation('image'),
+
     originDetails:
       relation('generateCoverArtworkOriginDetails', artwork),
 
@@ -19,10 +22,16 @@ export default {
       relation('generateCoverArtworkArtistDetails', artwork),
   }),
 
+  data: (artwork) => ({
+    path:
+      artwork.path,
+  }),
+
   slots: {
-    image: {
-      type: 'html',
-      mutable: true,
+    alt: {type: 'string'},
+
+    color: {
+      validate: v => v.isColor,
     },
 
     mode: {
@@ -48,16 +57,27 @@ export default {
     },
   },
 
-  generate(relations, slots, {html}) {
+  generate(data, relations, slots, {html}) {
+    const {image} = relations;
+
+    image.setSlots({
+      path: data.path,
+
+      color: slots.color,
+      alt: slots.alt,
+      warnings: slots.warnings,
+    });
+
     const square =
       (slots.dimensions
         ? slots.dimensions[0] === slots.dimensions[1]
         : true);
 
-    const sizeSlots =
-      (square
-        ? {square: true}
-        : {dimensions: slots.dimensions});
+    if (square) {
+      image.setSlot('square', true);
+    } else {
+      image.setSlot('dimensions', slots.dimensions);
+    }
 
     return (
       html.tag('div', {class: 'cover-artwork'},
@@ -66,13 +86,10 @@ export default {
 
         (slots.mode === 'primary'
           ? [
-              slots.image.slots({
+              relations.image.slots({
                 thumb: 'medium',
                 reveal: true,
                 link: true,
-
-                warnings: slots.warnings,
-                ...sizeSlots,
               }),
 
               slots.showOriginDetails &&
@@ -83,25 +100,21 @@ export default {
 
               slots.showArtistDetails &&
                 relations.artistDetails,
+
+              slots.details,
             ]
        : slots.mode === 'thumbnail'
-          ? slots.image.slots({
+          ? relations.image.slots({
               thumb: 'small',
               reveal: false,
               link: false,
-
-              warnings: slots.warnings,
-              ...sizeSlots,
             })
        : slots.mode === 'commentary'
-          ? slots.image.slots({
+          ? relations.image.slots({
               thumb: 'medium',
               reveal: true,
               link: true,
               lazy: true,
-
-              warnings: slots.warnings,
-              ...sizeSlots,
             })
           : html.blank())));
   },
diff --git a/src/content/dependencies/generateTrackCoverArtwork.js b/src/content/dependencies/generateTrackCoverArtwork.js
index 3fc219c8..52b61b87 100644
--- a/src/content/dependencies/generateTrackCoverArtwork.js
+++ b/src/content/dependencies/generateTrackCoverArtwork.js
@@ -14,9 +14,6 @@ export default {
     coverArtwork:
       relation('generateCoverArtwork', artwork),
 
-    image:
-      relation('image'),
-
     // referenceDetails:
     //   relation('generateCoverArtworkReferenceDetails',
     //     artwork.referencedArtworks,
@@ -35,16 +32,6 @@ export default {
   }),
 
   data: (artwork) => ({
-    path:
-      (artwork.thing.album
-        ? ['media.trackCover',
-           artwork.thing.album.directory,
-           artwork.thing.directory,
-           artwork.thing.coverArtFileExtension]
-        : ['media.albumCover',
-           artwork.thing.directory,
-           artwork.thing.coverArtFileExtension]),
-
     // color:
     //   track.color,
 
@@ -84,16 +71,12 @@ export default {
     },
   },
 
-  generate: (data, relations, slots, {html, language}) =>
+  generate: (data, relations, slots, {language}) =>
     relations.coverArtwork.slots({
       mode: slots.mode,
 
-      image:
-        relations.image.slots({
-          path: data.path,
-          // color: data.color,
-          alt: language.$('misc.alt.trackCover'),
-        }),
+      // color: data.color,
+      alt: language.$('misc.alt.trackCover'),
 
       dimensions: data.dimensions,
       warnings: data.warnings,
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 36069afb..606bc194 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -671,6 +671,14 @@ export class Album extends Thing {
       sortAlbumsTracksChronologically(trackData);
     },
   });
+
+  getOwnArtworkPath(_artwork) {
+    return [
+      'media.albumCover',
+      this.directory,
+      this.coverArtFileExtension,
+    ];
+  }
 }
 
 export class TrackSection extends Thing {
diff --git a/src/data/things/artwork.js b/src/data/things/artwork.js
index 24850057..bf5753b8 100644
--- a/src/data/things/artwork.js
+++ b/src/data/things/artwork.js
@@ -135,4 +135,11 @@ export class Artwork extends Thing {
       'Tags': {property: 'artTags'},
     },
   };
+
+  get path() {
+    if (!this.thing) return null;
+    if (!this.thing.getOwnArtworkPath) return null;
+
+    return this.thing.getOwnArtworkPath(this);
+  }
 }
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 7188178a..f514f7bb 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -724,6 +724,17 @@ export class Track extends Thing {
   // Track YAML loading is handled in album.js.
   static [Thing.getYamlLoadingSpec] = null;
 
+  getOwnArtworkPath(_artwork) {
+    if (!this.album) return null;
+
+    return [
+      'media.trackCover',
+      this.album.directory,
+      this.directory,
+      this.coverArtFileExtension,
+    ];
+  }
+
   [inspect.custom](depth) {
     const parts = [];