« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/generateReleaseInfoListenLine.js85
1 files changed, 56 insertions, 29 deletions
diff --git a/src/content/dependencies/generateReleaseInfoListenLine.js b/src/content/dependencies/generateReleaseInfoListenLine.js
index 8cc2c984..f2a6dd29 100644
--- a/src/content/dependencies/generateReleaseInfoListenLine.js
+++ b/src/content/dependencies/generateReleaseInfoListenLine.js
@@ -1,26 +1,60 @@
 import {isExternalLinkContext} from '#external-links';
 import {empty, stitchArrays, unique} from '#sugar';
 
+function getReleaseContext(urlString, {
+  _artistURLs,
+  albumArtistURLs,
+}) {
+  const composerBandcampDomains =
+    albumArtistURLs
+      .filter(url => url.hostname.endsWith('.bandcamp.com'))
+      .map(url => url.hostname);
+
+  const url = new URL(urlString);
+
+  if (url.hostname === 'homestuck.bandcamp.com') {
+    return 'officialRelease';
+  }
+
+  if (composerBandcampDomains.includes(url.hostname)) {
+    return 'composerRelease';
+  }
+
+  return null;
+}
+
 export default {
   contentDependencies: ['linkExternal'],
   extraDependencies: ['html', 'language'],
 
-  query: (thing) => ({
-    album:
+  query(thing) {
+    const query = {};
+
+    query.album =
       (thing.album
         ? thing.album
-        : thing),
+        : thing);
 
-    artists:
+    query.artists =
       thing.artistContribs
-        .map(contrib => contrib.artist),
+        .map(contrib => contrib.artist);
 
-    artistGroups:
-      thing.artistContribs
-        .map(contrib => contrib.artist)
+    query.artistGroups =
+      query.artists
         .flatMap(artist => artist.closelyLinkedGroups)
-        .map(({group}) => group),
-  }),
+        .map(({group}) => group);
+
+    query.albumArtists =
+      query.album.artistContribs
+        .map(contrib => contrib.artist);
+
+    query.albumArtistGroups =
+      query.albumArtists
+        .flatMap(artist => artist.closelyLinkedGroups)
+        .map(({group}) => group);
+
+    return query;
+  },
 
   relations: (relation, _query, thing) => ({
     links:
@@ -38,30 +72,23 @@ export default {
         ...query.artistGroups.flatMap(group => group.urls),
       ]).map(url => new URL(url));
 
-    const artistBandcampDomains =
-      artistURLs
-        .filter(url => url.hostname.endsWith('.bandcamp.com'))
-        .map(url => url.hostname);
-
-    const getReleaseContext = urlString => {
-      const url = new URL(urlString);
-
-      if (url.hostname === 'homestuck.bandcamp.com') {
-        return 'officialRelease';
-      }
-
-      if (artistBandcampDomains.includes(url.hostname)) {
-        return 'artistRelease';
-      }
+    const albumArtistURLs =
+      unique([
+        ...query.albumArtists.flatMap(artist => artist.urls),
+        ...query.albumArtistGroups.flatMap(group => group.urls),
+      ]).map(url => new URL(url));
 
-      return null;
-    };
+    const boundGetReleaseContext = urlString =>
+      getReleaseContext(urlString, {
+        artistURLs,
+        albumArtistURLs,
+      });
 
     let releaseContexts =
-      thing.urls.map(getReleaseContext);
+      thing.urls.map(boundGetReleaseContext);
 
     const albumReleaseContexts =
-      query.album.urls.map(getReleaseContext);
+      query.album.urls.map(boundGetReleaseContext);
 
     const presentReleaseContexts =
       unique(releaseContexts.filter(Boolean));