« 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/generateArtistInfoPage.js67
-rw-r--r--src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js111
2 files changed, 115 insertions, 63 deletions
diff --git a/src/content/dependencies/generateArtistInfoPage.js b/src/content/dependencies/generateArtistInfoPage.js
index a3d159af..6956244b 100644
--- a/src/content/dependencies/generateArtistInfoPage.js
+++ b/src/content/dependencies/generateArtistInfoPage.js
@@ -5,6 +5,7 @@ export default {
   contentDependencies: [
     'generateArtistGroupContributionsInfo',
     'generateArtistInfoPageArtworksChunkedList',
+    'generateArtistInfoPageCommentaryChunkedList',
     'generateArtistInfoPageFlashesChunkedList',
     'generateArtistInfoPageTracksChunkedList',
     'generateArtistNavLinks',
@@ -99,51 +100,11 @@ export default {
       flashes.list = relation('generateArtistInfoPageFlashesChunkedList', artist);
     }
 
-    /*
-    // Commentary doesn't use the detailed contribution system where multiple
-    // artists are collaboratively credited for the same piece, so there isn't
-    // really anything special to do for processing or presenting it.
-
-    const commentaryEntries = [
-      ...artist.albumsAsCommentator.map(album => ({
-        kind: 'albumCommentary',
-        date: album.date,
-        thing: album,
-        album: album,
-      })),
-
-      ...artist.tracksAsCommentator.map(track => ({
-        kind: 'trackCommentary',
-        date: track.date,
-        thing: track,
-        album: track.album,
-        trackLink: relation('linkTrack', track),
-      })),
-    ];
-
-    sortContributionEntries(commentaryEntries, sortAlbumsTracksChronologically);
-
-    // We still pass through (and chunk by) date here, even though it doesn't
-    // actually get displayed on the album page. See issue #193.
-    const commentaryChunks =
-      chunkByProperties(commentaryEntries, ['album', 'date'])
-        .map(({album, date, chunk}) => ({
-          albumLink: relation('linkAlbum', album),
-          date: +date,
-          entries:
-            chunk.map(entry =>
-              filterProperties(entry, [
-                'kind',
-                'trackLink',
-              ])),
-        }));
-
-    if (!empty(commentaryChunks)) {
+    if (!empty(artist.albumsAsCommentator) || !empty(artist.tracksAsCommentator)) {
       const commentary = sections.commentary = {};
       commentary.heading = relation('generateContentHeading');
-      commentary.chunks = commentaryChunks;
+      commentary.list = relation('generateArtistInfoPageCommentaryChunkedList', artist);
     }
-    */
 
     return relations;
   },
@@ -295,7 +256,6 @@ export default {
             sec.flashes.list,
           ],
 
-          /*
           sec.commentary && [
             sec.commentary.heading
               .slots({
@@ -304,27 +264,8 @@ export default {
                 title: language.$('artistPage.commentaryList.title'),
               }),
 
-            html.tag('dl',
-              sec.commentary.chunks.map(({albumLink, entries}) => [
-                html.tag('dt',
-                  language.$('artistPage.creditList.album', {
-                    album: albumLink,
-                  })),
-
-                html.tag('dd',
-                  html.tag('ul',
-                    entries
-                      .map(({kind, trackLink}) =>
-                        (kind === 'trackCommentary'
-                          ? language.$('artistPage.creditList.entry.track', {
-                              track: trackLink,
-                            })
-                          : html.tag('i',
-                              language.$('artistPage.creditList.entry.album.commentary'))))
-                      .map(entry => html.tag('li', entry)))),
-              ])),
+            sec.commentary.list,
           ],
-          */
         ],
 
         navLinkStyle: 'hierarchical',
diff --git a/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js b/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
new file mode 100644
index 00000000..5e5e9819
--- /dev/null
+++ b/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
@@ -0,0 +1,111 @@
+import {stitchArrays} from '../../util/sugar.js';
+
+import {
+  chunkByProperties,
+  sortAlbumsTracksChronologically,
+  sortEntryThingPairs,
+} from '../../util/wiki-data.js';
+
+export default {
+  contentDependencies: [
+    'generateArtistInfoPageChunk',
+    'generateArtistInfoPageChunkItem',
+    'generateArtistInfoPageOtherArtistLinks',
+    'linkAlbum',
+    'linkTrack',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  query(artist) {
+    // TODO: Add and integrate wallpaper and banner date fields (#90)
+    // This will probably only happen once all artworks follow a standard
+    // shape (#70) and get their own sorting function. Read for more info:
+    // https://github.com/hsmusic/hsmusic-wiki/issues/90#issuecomment-1607422961
+
+    const entries = [
+      ...artist.albumsAsCommentator.map(album => ({
+        thing: album,
+        entry: {
+          type: 'album',
+          album,
+        },
+      })),
+
+      ...artist.tracksAsContributor.map(track => ({
+        thing: track,
+        entry: {
+          type: 'track',
+          album: track.album,
+          track,
+        },
+      })),
+    ];
+
+    sortEntryThingPairs(entries, sortAlbumsTracksChronologically);
+
+    const chunks =
+      chunkByProperties(
+        entries.map(({entry}) => entry),
+        ['album']);
+
+    return {chunks};
+  },
+
+  relations(relation, query) {
+    return {
+      chunks:
+        query.chunks.map(() => relation('generateArtistInfoPageChunk')),
+
+      albumLinks:
+        query.chunks.map(({album}) => relation('linkAlbum', album)),
+
+      items:
+        query.chunks.map(({chunk}) =>
+          chunk.map(() => relation('generateArtistInfoPageChunkItem'))),
+
+      itemTrackLinks:
+        query.chunks.map(({chunk}) =>
+          chunk.map(({track}) => track ? relation('linkTrack', track) : null)),
+    };
+  },
+
+  data(query) {
+    return {
+      itemTypes:
+        query.chunks.map(({chunk}) =>
+          chunk.map(({type}) => type)),
+    };
+  },
+
+  generate(data, relations, {html, language}) {
+    return html.tag('dl',
+      stitchArrays({
+        chunk: relations.chunks,
+        albumLink: relations.albumLinks,
+
+        items: relations.items,
+        itemTrackLinks: relations.itemTrackLinks,
+        itemTypes: data.itemTypes,
+      }).map(({chunk, albumLink, items, itemTrackLinks, itemTypes}) =>
+          chunk.slots({
+            mode: 'album',
+            albumLink,
+            items:
+              stitchArrays({
+                item: items,
+                trackLink: itemTrackLinks,
+                type: itemTypes,
+              }).map(({item, trackLink, type}) =>
+                item.slots({
+                  content:
+                    (type === 'album'
+                      ? html.tag('i',
+                          language.$('artistPage.creditList.entry.album.commentary'))
+                      : language.$('artistPage.creditList.entry.track', {
+                          track: trackLink,
+                        })),
+                })),
+          })));
+  },
+};