« get me outta code hell

content: generateArtistInfoPageCommentaryChunkedList - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-06-30 17:09:10 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-30 17:09:10 -0300
commitc0d76a612f3a1db99c60f494d2bdcc05fa7c6679 (patch)
tree021aa89eaac5c9c2e00339f9a53b9808b0cd5498 /src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
parent6758dd090ba6c3c7ea84a4b7d6fab0a0c26ad13e (diff)
content: generateArtistInfoPageCommentaryChunkedList
Diffstat (limited to 'src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js')
-rw-r--r--src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js b/src/content/dependencies/generateArtistInfoPageCommentaryChunkedList.js
new file mode 100644
index 0000000..5e5e981
--- /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,
+                        })),
+                })),
+          })));
+  },
+};