« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateTrackListItem.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateTrackListItem.js')
-rw-r--r--src/content/dependencies/generateTrackListItem.js76
1 files changed, 40 insertions, 36 deletions
diff --git a/src/content/dependencies/generateTrackListItem.js b/src/content/dependencies/generateTrackListItem.js
index 3c850a18..c8c57534 100644
--- a/src/content/dependencies/generateTrackListItem.js
+++ b/src/content/dependencies/generateTrackListItem.js
@@ -1,21 +1,19 @@
 export default {
-  contentDependencies: [
-    'generateArtistCredit',
-    'generateColorStyleAttribute',
-    'generateTrackListMissingDuration',
-    'linkTrack',
-  ],
-
-  extraDependencies: ['html', 'language'],
-
   relations: (relation, track, contextContributions) => ({
     trackLink:
       relation('linkTrack', track),
 
-    credit:
+    contextualCredit:
+      relation('generateArtistCredit',
+        track.artistContribs,
+        contextContributions,
+        track.artistTextInLists),
+
+    acontextualCredit:
       relation('generateArtistCredit',
         track.artistContribs,
-        contextContributions),
+        [],
+        track.artistTextInLists),
 
     colorStyle:
       relation('generateColorStyleAttribute', track.color),
@@ -35,12 +33,11 @@ export default {
   }),
 
   slots: {
-    // showArtists enables showing artists *at all.* It doesn't take precedence
-    // over behavior which automatically collapses (certain) artists because of
-    // provided context contributions.
+    // true always shows artists, false never does; 'auto' shows only if
+    // the track's artists differ from the given context contributions.
     showArtists: {
-      type: 'boolean',
-      default: true,
+      validate: v => v.is(true, false, 'auto'),
+      default: 'auto',
     },
 
     // If true and the track doesn't have a duration, a missing-duration cue
@@ -80,26 +77,33 @@ export default {
                 : relations.missingDuration);
           }
 
-          const artistCapsule = language.encapsulate(itemCapsule, 'withArtists');
-
-          relations.credit.setSlots({
-            normalStringKey:
-              artistCapsule + '.by',
-
-            featuringStringKey:
-              artistCapsule + '.featuring',
-
-            normalFeaturingStringKey:
-              artistCapsule + '.by.featuring',
-          });
-
-          if (!html.isBlank(relations.credit)) {
-            workingCapsule += '.withArtists';
-            workingOptions.by =
-              html.tag('span', {class: 'by'},
-                // TODO: This is obviously evil.
-                html.metatag('chunkwrap', {split: /,| (?=and)/},
-                  html.resolve(relations.credit)));
+          const chosenCredit =
+            (slots.showArtists === true
+              ? relations.acontextualCredit
+           : slots.showArtists === 'auto'
+              ? relations.contextualCredit
+              : null);
+
+          if (chosenCredit) {
+            const artistCapsule = language.encapsulate(itemCapsule, 'withArtists');
+
+            chosenCredit.setSlots({
+              normalStringKey:
+                artistCapsule + '.by',
+
+              featuringStringKey:
+                artistCapsule + '.featuring',
+
+              normalFeaturingStringKey:
+                artistCapsule + '.by.featuring',
+            });
+
+            if (!html.isBlank(chosenCredit)) {
+              workingCapsule += '.withArtists';
+              workingOptions.by =
+                html.tag('span', {class: 'by'},
+                  chosenCredit);
+            }
           }
 
           return language.$(workingCapsule, workingOptions);