« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content/dependencies/generateArtistInfoPageChunkItem.js4
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunkedList.js25
-rw-r--r--src/data/things/track.js61
-rw-r--r--src/data/yaml.js2
-rw-r--r--src/find.js24
-rw-r--r--src/gen-thumbs.js2
-rw-r--r--src/static/client2.js2
7 files changed, 83 insertions, 37 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageChunkItem.js b/src/content/dependencies/generateArtistInfoPageChunkItem.js
index 36f0ebcc..9f99513d 100644
--- a/src/content/dependencies/generateArtistInfoPageChunkItem.js
+++ b/src/content/dependencies/generateArtistInfoPageChunkItem.js
@@ -5,7 +5,7 @@ export default {
     content: {type: 'html'},
 
     otherArtistLinks: {validate: v => v.strictArrayOf(v.isHTML)},
-    contribution: {type: 'string'},
+    contribution: {type: 'html'},
     rerelease: {type: 'boolean'},
   },
 
@@ -30,7 +30,7 @@ export default {
         options.artists = language.formatConjunctionList(slots.otherArtistLinks);
       }
 
-      if (slots.contribution) {
+      if (!html.isBlank(slots.contribution)) {
         parts.push('withContribution');
         options.contribution = slots.contribution;
       }
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
index 0566f713..654f759c 100644
--- a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
@@ -1,4 +1,4 @@
-import {accumulateSum, stitchArrays} from '#sugar';
+import {accumulateSum, empty, stitchArrays} from '#sugar';
 
 import {
   chunkByProperties,
@@ -16,7 +16,7 @@ export default {
     'linkTrack',
   ],
 
-  extraDependencies: ['language'],
+  extraDependencies: ['html', 'language'],
 
   query(artist) {
     const tracksAsArtistAndContributor =
@@ -122,11 +122,16 @@ export default {
 
       trackContributions:
         query.chunks.map(({chunk}) =>
-          chunk.map(({contribs}) =>
-            contribs
-              .filter(({who}) => who === artist)
-              .filter(({what}) => what)
-              .map(({what}) => what))),
+          chunk
+            .map(({contribs}) =>
+              contribs
+                .filter(({who}) => who === artist)
+                .filter(({what}) => what)
+                .map(({what}) => what))
+            .map(contributions =>
+              (empty(contributions)
+                ? null
+                : contributions))),
 
       trackRereleases:
         query.chunks.map(({chunk}) =>
@@ -134,7 +139,7 @@ export default {
     };
   },
 
-  generate(data, relations, {language}) {
+  generate(data, relations, {html, language}) {
     return relations.chunkedList.slots({
       chunks:
         stitchArrays({
@@ -192,7 +197,9 @@ export default {
                       rerelease,
 
                       contribution:
-                        language.formatUnitList(contribution),
+                        (contribution
+                          ? language.formatUnitList(contribution)
+                          : html.blank()),
 
                       content:
                         (duration
diff --git a/src/data/things/track.js b/src/data/things/track.js
index b41dbb5b..28caf1de 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -61,17 +61,51 @@ export class Track extends Thing {
     dateFirstReleased: simpleDate(),
 
     color: [
-      exposeUpdateValueOrContinue(),
+      exposeUpdateValueOrContinue({
+        validate: input.value(isColor),
+      }),
 
       withContainingTrackSection(),
       withPropertyFromObject({object: '#trackSection', property: 'color'}),
       exposeDependencyOrContinue({dependency: '#trackSection.color'}),
 
       withPropertyFromAlbum({property: 'color'}),
-      exposeDependency({
-        dependency: '#album.color',
-        update: {validate: isColor},
+      exposeDependency({dependency: '#album.color'}),
+    ],
+
+    // Controls how find.track works - it'll never be matched by a reference
+    // just to the track's name, which means you don't have to always reference
+    // some *other* (much more commonly referenced) track by directory instead
+    // of more naturally by name.
+    alwaysReferenceByDirectory: [
+      exposeUpdateValueOrContinue({
+        validate: input.value(isBoolean),
       }),
+
+      excludeFromList({
+        list: 'trackData',
+        item: input.myself(),
+      }),
+
+      withOriginalRelease({
+        data: '#trackData',
+      }),
+
+      exitWithoutDependency({
+        dependency: '#originalRelease',
+        value: input.value(false),
+      }),
+
+      withPropertyFromObject({
+        object: '#originalRelease',
+        property: input.value('name'),
+      }),
+
+      {
+        dependencies: ['name', '#originalRelease.name'],
+        compute({name, '#originalRelease.name': originalName}) =>
+          name === originalName,
+      },
     ],
 
     // Disables presenting the track as though it has its own unique artwork.
@@ -506,6 +540,9 @@ export const withOriginalRelease = templateCompositeFrom({
 
   inputs: {
     selfIfOriginal: input({type: 'boolean', defaultValue: false}),
+
+    // todo: validate
+    data: input({defaultDependency: 'trackData'}),
   },
 
   outputs: {
@@ -513,14 +550,14 @@ export const withOriginalRelease = templateCompositeFrom({
   },
 
   steps: () => [
-    withResolvedReference
-      .inputs({
-        ref: 'originalReleaseTrack',
-        data: 'trackData',
-        find: input.value(find.track),
-        notFoundMode: input.value('exit'),
-      })
-      .outputs({into: '#originalRelease'}),
+    withResolvedReference({
+      ref: 'originalReleaseTrack',
+      data: input('data'),
+      find: input.value(find.track),
+      notFoundMode: input.value('exit'),
+    }).outputs({
+      '#resolvedReference': '#originalRelease',
+    }),
 
     {
       dependencies: [
diff --git a/src/data/yaml.js b/src/data/yaml.js
index e1e5803d..c799be5f 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -342,6 +342,8 @@ export const processTrackDocument = makeProcessDocument(T.Track, {
     coverArtFileExtension: 'Cover Art File Extension',
     disableUniqueCoverArt: 'Has Cover Art', // This gets transformed to flip true/false.
 
+    alwaysReferenceByDirectory: 'Always Reference By Directory',
+
     lyrics: 'Lyrics',
     commentary: 'Commentary',
     additionalFiles: 'Additional Files',
diff --git a/src/find.js b/src/find.js
index 5ad8dae7..66f705e4 100644
--- a/src/find.js
+++ b/src/find.js
@@ -80,17 +80,19 @@ function matchDirectory(ref, data) {
 }
 
 function matchName(ref, data, mode) {
-  const matches = data.filter(
-    ({name}) => name.toLowerCase() === ref.toLowerCase()
-  );
+  const matches =
+    data
+      .filter(({name}) => name.toLowerCase() === ref.toLowerCase())
+      .filter(thing =>
+        (Object.hasOwn(thing, 'alwaysReferenceByDirectory')
+          ? !thing.alwaysReferenceByDirectory
+          : true));
 
   if (matches.length > 1) {
-    return warnOrThrow(
-      mode,
+    return warnOrThrow(mode,
       `Multiple matches for reference "${ref}". Please resolve:\n` +
-        matches.map((match) => `- ${inspect(match)}\n`).join('') +
-        `Returning null for this reference.`
-    );
+      matches.map(match => `- ${inspect(match)}\n`).join('') +
+      `Returning null for this reference.`);
   }
 
   if (matches.length === 0) {
@@ -100,10 +102,8 @@ function matchName(ref, data, mode) {
   const thing = matches[0];
 
   if (ref !== thing.name) {
-    warnOrThrow(
-      mode,
-      `Bad capitalization: ${colors.red(ref)} -> ${colors.green(thing.name)}`
-    );
+    warnOrThrow(mode,
+      `Bad capitalization: ${colors.red(ref)} -> ${colors.green(thing.name)}`);
   }
 
   return thing;
diff --git a/src/gen-thumbs.js b/src/gen-thumbs.js
index f59bc620..e99b9602 100644
--- a/src/gen-thumbs.js
+++ b/src/gen-thumbs.js
@@ -674,7 +674,7 @@ export async function verifyImagePaths(mediaPath, {urls, wikiData}) {
 
   if (empty(missing) && empty(misplaced)) {
     logInfo`All image paths are good - nice! None are missing or misplaced.`;
-    return;
+    return {missing, misplaced};
   }
 
   if (!empty(missing)) {
diff --git a/src/static/client2.js b/src/static/client2.js
index 78970410..d9afcb03 100644
--- a/src/static/client2.js
+++ b/src/static/client2.js
@@ -539,7 +539,7 @@ const stickyHeadingInfo = Array.from(document.querySelectorAll('.content-sticky-
     const contentHeadings = Array.from(contentContainer.querySelectorAll('.content-heading'));
     const contentCover = contentContainer.querySelector('#cover-art-container');
 
-    if (stickyCover.querySelector('.image-text-area')) {
+    if (stickyCover?.querySelector('.image-text-area')) {
       stickyCoverContainer.remove();
       stickyCoverContainer = null;
       stickyCover = null;