« get me outta code hell

content: gAIPTracksChunkedList: stub separate-components refactor - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-06 17:01:02 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-12 17:26:38 -0300
commit3d51b9e53029c3995ad4a90c4dda93bdb696ae29 (patch)
tree33c6c11d09b92a47f0b41397f77547a4304b7159 /src
parent878e09f8131fcf17f7a21ba1b5dbfdf6d9ad41e8 (diff)
content: gAIPTracksChunkedList: stub separate-components refactor
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateArtistInfoPage.js3
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunk.js52
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunkItem.js109
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunkedList.js218
4 files changed, 181 insertions, 201 deletions
diff --git a/src/content/dependencies/generateArtistInfoPage.js b/src/content/dependencies/generateArtistInfoPage.js
index 28b9e1d3..d1941b91 100644
--- a/src/content/dependencies/generateArtistInfoPage.js
+++ b/src/content/dependencies/generateArtistInfoPage.js
@@ -1,5 +1,4 @@
 import {empty, unique} from '#sugar';
-import {getTotalDuration} from '#wiki-data';
 
 export default {
   contentDependencies: [
@@ -127,7 +126,7 @@ export default {
     }
 
     data.totalTrackCount = query.allTracks.length;
-    data.totalDuration = getTotalDuration(query.allTracks, {originalReleasesOnly: true});
+    data.totalDuration = artist.totalDuration;
 
     return data;
   },
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunk.js b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
new file mode 100644
index 00000000..b27a2988
--- /dev/null
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunk.js
@@ -0,0 +1,52 @@
+import {stitchArrays} from '#sugar';
+import {getTotalDuration} from '#wiki-data';
+
+export default {
+  contentDependencies: [
+    'generateArtistInfoPageChunk',
+    'generateArtistInfoPageTracksChunkItem',
+    'linkAlbum',
+  ],
+
+  relations: (relation, artist, album, tracks, contribs) => ({
+    template:
+      relation('generateArtistInfoPageChunk'),
+
+    albumLink:
+      relation('linkAlbum', album),
+
+    items:
+      stitchArrays({
+        track: tracks,
+        contribs: contribs,
+      }).map(({track, contribs}) =>
+          relation('generateArtistInfoPageTracksChunkItem',
+            artist,
+            track,
+            contribs)),
+  }),
+
+  data: (_artist, album, tracks, _contribs) => ({
+    // STUB: This is flat-out incorrect date behavior.
+    date:
+      album.date,
+
+    duration:
+      getTotalDuration(tracks, {originalReleasesOnly: true}),
+
+    durationApproximate:
+      tracks
+        .filter(track => track.duration && track.isOriginalRelease)
+        .length > 1,
+  }),
+
+  generate: (data, relations) =>
+    relations.template.slots({
+      mode: 'album',
+      albumLink: relations.albumLink,
+      date: data.date,
+      duration: data.duration,
+      durationApproximate: data.durationApproximate,
+      items: relations.items,
+    }),
+};
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunkItem.js b/src/content/dependencies/generateArtistInfoPageTracksChunkItem.js
new file mode 100644
index 00000000..d69ee30e
--- /dev/null
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunkItem.js
@@ -0,0 +1,109 @@
+import {empty} from '#sugar';
+
+export default {
+  contentDependencies: [
+    'generateArtistInfoPageChunkItem',
+    'generateArtistInfoPageOtherArtistLinks',
+    'linkTrack',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  query (_artist, track, contribs) {
+    const query = {};
+
+    const creditedAsArtist =
+      contribs
+        .some(contrib => contrib.kind === 'artist');
+
+    const creditedAsContributor =
+      contribs
+        .some(contrib => contrib.kind === 'contributor');
+
+    const annotatedContribs =
+      contribs
+        .filter(contrib => contrib.annotation);
+
+    const annotatedArtistContribs =
+      annotatedContribs
+        .filter(contrib => contrib.kind === 'artist');
+
+    const annotatedContributorContribs =
+      annotatedContribs
+        .filter(contrib => contrib.kind === 'contributor');
+
+    // Don't display annotations associated with crediting in the
+    // Contributors field if the artist is also credited as an Artist
+    // *and* the Artist-field contribution is non-annotated. This is
+    // so that we don't misrepresent the artist - the contributor
+    // annotation tends to be for "secondary" and performance roles.
+    // For example, this avoids crediting Marcy Nabors on Renewed
+    // Return seemingly only for "bass clarinet" when they're also
+    // the one who composed and arranged Renewed Return!
+    if (
+      creditedAsArtist &&
+      creditedAsContributor &&
+      empty(annotatedArtistContribs)
+    ) {
+      query.displayedContributions = null;
+    } else if (
+      !empty(annotatedArtistContribs) ||
+      !empty(annotatedContributorContribs)
+    ) {
+      query.displayedContributions = [
+        ...annotatedArtistContribs,
+        ...annotatedContributorContribs,
+      ];
+    }
+
+    return query;
+  },
+
+  relations: (relation, _query, artist, track, contribs) => ({
+    template:
+      relation('generateArtistInfoPageChunkItem'),
+
+    trackLink:
+      relation('linkTrack', track),
+
+    otherArtistLinks:
+      relation('generateArtistInfoPageOtherArtistLinks',
+        contribs,
+        artist),
+  }),
+
+  data: (query, _artist, track, _contribs) => ({
+    duration:
+      track.duration,
+
+    rerelease:
+      track.isRerelease,
+
+    contribAnnotations:
+      (query.displayedContributions
+        ? query.displayedContributions
+            .map(contrib => contrib.annotation)
+        : null),
+  }),
+
+  generate: (data, relations, {html, language}) =>
+    relations.template.slots({
+      otherArtistLinks: relations.otherArtistLinks,
+      rerelease: data.rerelease,
+
+      annotation:
+        (data.contribAnnotations
+          ? language.formatUnitList(data.contribAnnotations)
+          : html.blank()),
+
+      content:
+        (data.duration
+          ? language.$('artistPage.creditList.entry.track.withDuration', {
+              track: relations.trackLink,
+              duration: language.formatDuration(data.duration),
+            })
+          : language.$('artistPage.creditList.entry.track', {
+              track: relations.trackLink,
+            })),
+    }),
+};
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
index bce6cedf..6a1a1700 100644
--- a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
@@ -1,18 +1,12 @@
 import {sortAlbumsTracksChronologically, sortEntryThingPairs} from '#sort';
-import {accumulateSum, chunkByProperties, empty, stitchArrays} from '#sugar';
+import {chunkByProperties, stitchArrays} from '#sugar';
 
 export default {
   contentDependencies: [
-    'generateArtistInfoPageChunk',
     'generateArtistInfoPageChunkedList',
-    'generateArtistInfoPageChunkItem',
-    'generateArtistInfoPageOtherArtistLinks',
-    'linkAlbum',
-    'linkTrack',
+    'generateArtistInfoPageTracksChunk',
   ],
 
-  extraDependencies: ['html', 'language'],
-
   query(artist) {
     const processTrackEntry = ({track, contribs}) => ({
       thing: track,
@@ -99,195 +93,21 @@ export default {
     return {chunks};
   },
 
-  relations(relation, query, artist) {
-    return {
-      chunkedList:
-        relation('generateArtistInfoPageChunkedList'),
-
-      chunks:
-        query.chunks.map(() => relation('generateArtistInfoPageChunk')),
-
-      albumLinks:
-        query.chunks.map(({album}) => relation('linkAlbum', album)),
-
-      items:
-        query.chunks.map(({chunk}) =>
-          chunk.map(() => relation('generateArtistInfoPageChunkItem'))),
-
-      trackLinks:
-        query.chunks.map(({chunk}) =>
-          chunk.map(({track}) => relation('linkTrack', track))),
-
-      trackOtherArtistLinks:
-        query.chunks.map(({chunk}) =>
-          chunk.map(({contribs}) => relation('generateArtistInfoPageOtherArtistLinks', contribs, artist))),
-    };
-  },
-
-  data(query, artist) {
-    return {
-      chunkDates:
-        query.chunks.map(({date}) => date),
-
-      chunkDurations:
-        query.chunks.map(({chunk}) =>
-          accumulateSum(
-            chunk
-              .filter(({track}) => track.duration && track.originalReleaseTrack === null)
-              .map(({track}) => track.duration))),
-
-      chunkDurationsApproximate:
-        query.chunks.map(({chunk}) =>
-          chunk
-            .filter(({track}) => track.duration && track.originalReleaseTrack === null)
-            .length > 1),
-
-      trackDurations:
-        query.chunks.map(({chunk}) =>
-          chunk.map(({track}) => track.duration)),
-
-      trackContributions:
-        query.chunks.map(({chunk}) =>
-          chunk
-            .map(({contribs}) =>
-              contribs.filter(contrib => contrib.artist === artist))
-            .map(ownContribs => ({
-              creditedAsArtist:
-                ownContribs
-                  .some(({kind}) => kind === 'artist'),
-
-              creditedAsContributor:
-                ownContribs
-                  .some(({kind}) => kind === 'contributor'),
-
-              annotatedContribs:
-                ownContribs
-                  .filter(({annotation}) => annotation),
-            }))
-            .map(({annotatedContribs, ...rest}) => ({
-              ...rest,
-
-              annotatedArtistContribs:
-                annotatedContribs
-                  .filter(({kind}) => kind === 'artist'),
-
-              annotatedContributorContribs:
-                annotatedContribs
-                  .filter(({kind}) => kind === 'contributor'),
-            }))
-            .map(({
-              creditedAsArtist,
-              creditedAsContributor,
-              annotatedArtistContribs,
-              annotatedContributorContribs,
-            }) => {
-              // Don't display annotations associated with crediting in the
-              // Contributors field if the artist is also credited as an Artist
-              // *and* the Artist-field contribution is non-annotated. This is
-              // so that we don't misrepresent the artist - the contributor
-              // annotation tends to be for "secondary" and performance roles.
-              // For example, this avoids crediting Marcy Nabors on Renewed
-              // Return seemingly only for "bass clarinet" when they're also
-              // the one who composed and arranged Renewed Return!
-              if (
-                creditedAsArtist &&
-                creditedAsContributor &&
-                empty(annotatedArtistContribs)
-              ) {
-                return [];
-              }
-
-              return [
-                ...annotatedArtistContribs,
-                ...annotatedContributorContribs,
-              ];
-            })
-            .map(contribs =>
-              contribs.map(({annotation}) => annotation))
-            .map(contributions =>
-              (empty(contributions)
-                ? null
-                : contributions))),
-
-      trackRereleases:
-        query.chunks.map(({chunk}) =>
-          chunk.map(({track}) => track.originalReleaseTrack !== null)),
-    };
-  },
-
-  generate(data, relations, {html, language}) {
-    return relations.chunkedList.slots({
-      chunks:
-        stitchArrays({
-          chunk: relations.chunks,
-          albumLink: relations.albumLinks,
-          date: data.chunkDates,
-          duration: data.chunkDurations,
-          durationApproximate: data.chunkDurationsApproximate,
-
-          items: relations.items,
-          trackLinks: relations.trackLinks,
-          trackOtherArtistLinks: relations.trackOtherArtistLinks,
-          trackDurations: data.trackDurations,
-          trackContributions: data.trackContributions,
-          trackRereleases: data.trackRereleases,
-        }).map(({
-            chunk,
-            albumLink,
-            date,
-            duration,
-            durationApproximate,
-
-            items,
-            trackLinks,
-            trackOtherArtistLinks,
-            trackDurations,
-            trackContributions,
-            trackRereleases,
-          }) =>
-            chunk.slots({
-              mode: 'album',
-              albumLink,
-              date,
-              duration,
-              durationApproximate,
-
-              items:
-                stitchArrays({
-                  item: items,
-                  trackLink: trackLinks,
-                  otherArtistLinks: trackOtherArtistLinks,
-                  duration: trackDurations,
-                  contribution: trackContributions,
-                  rerelease: trackRereleases,
-                }).map(({
-                    item,
-                    trackLink,
-                    otherArtistLinks,
-                    duration,
-                    contribution,
-                    rerelease,
-                  }) =>
-                    item.slots({
-                      otherArtistLinks,
-                      rerelease,
-
-                      annotation:
-                        (contribution
-                          ? language.formatUnitList(contribution)
-                          : html.blank()),
-
-                      content:
-                        (duration
-                          ? language.$('artistPage.creditList.entry.track.withDuration', {
-                              track: trackLink,
-                              duration: language.formatDuration(duration),
-                            })
-                          : language.$('artistPage.creditList.entry.track', {
-                              track: trackLink,
-                            })),
-                    })),
-            })),
-    });
-  },
+  relations: (relation, query, artist) => ({
+    chunkedList:
+      relation('generateArtistInfoPageChunkedList'),
+
+    chunks:
+      query.chunks.map(({chunk, album}) =>
+        relation('generateArtistInfoPageTracksChunk',
+          artist,
+          album,
+          chunk.map(entry => entry.track),
+          chunk.map(entry => entry.contribs))),
+  }),
+
+  generate: (relations) =>
+    relations.chunkedList.slots({
+      chunks: relations.chunks,
+    }),
 };