« get me outta code hell

content: generateArtistInfoPageFlashesChunkedList - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-06-27 21:21:14 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-27 21:21:14 -0300
commitecde71b903a89607bf8c5032a1cda61a3ff1b3c5 (patch)
tree0359750c2fcafe28e6a1e883113e4f219e84eae3 /src/content/dependencies
parentd3f13b864dddec7ef191aca769794695323ed498 (diff)
content: generateArtistInfoPageFlashesChunkedList
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateArtistInfoPage.js97
-rw-r--r--src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js2
-rw-r--r--src/content/dependencies/generateArtistInfoPageChunk.js67
-rw-r--r--src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js134
-rw-r--r--src/content/dependencies/generateArtistInfoPageTracksChunkedList.js1
5 files changed, 194 insertions, 107 deletions
diff --git a/src/content/dependencies/generateArtistInfoPage.js b/src/content/dependencies/generateArtistInfoPage.js
index 561ae652..bfb3d601 100644
--- a/src/content/dependencies/generateArtistInfoPage.js
+++ b/src/content/dependencies/generateArtistInfoPage.js
@@ -4,16 +4,15 @@ import {getTotalDuration} from '../../util/wiki-data.js';
 export default {
   contentDependencies: [
     'generateArtistInfoPageArtworksChunkedList',
+    'generateArtistInfoPageFlashesChunkedList',
     'generateArtistInfoPageTracksChunkedList',
     'generateArtistNavLinks',
     'generateContentHeading',
     'generateCoverArtwork',
     'generatePageLayout',
     'linkAlbum',
-    'linkArtist',
     'linkArtistGallery',
     'linkExternal',
-    'linkFlash',
     'linkGroup',
     'linkTrack',
     'transformContent',
@@ -115,68 +114,11 @@ export default {
       // }
     }
 
-    /*
-    sortContributionEntries(artContributionEntries, sortAlbumsTracksChronologically);
-
-    const artContributionChunks =
-      chunkByProperties(artContributionEntries, ['album', 'date'])
-        .map(({album, date, chunk}) => ({
-          albumLink: relation('linkAlbum', album),
-          date: +date,
-          entries:
-            chunk.map(entry =>
-              filterProperties(entry, [
-                'contributionDescription',
-                'kind',
-                'otherArtistLinks',
-                'rerelease',
-                'trackLink',
-              ])),
-        }));
-    */
-
-    /*
-    // Flashes and games can list multiple contributors as collaborative
-    // credits, but we don't display these on the artist page, since they
-    // usually involve many artists crediting a larger team where collaboration
-    // isn't as relevant (without more particular details that aren't tracked
-    // on the wiki).
-
-    if (sprawl.enableFlashesAndGames) {
-      const flashEntries = [
-        ...artist.flashesAsContributor.map(flash => ({
-          date: +flash.date,
-          thing: flash,
-          act: flash.act,
-          flashLink: relation('linkFlash', flash),
-          // ...getContributionDescription(flash.contributorContribs),
-        })),
-      ];
-
-      sortContributionEntries(flashEntries, sortFlashesChronologically);
-
-      const flashChunks =
-        chunkByProperties(flashEntries, ['act'])
-          .map(({act, chunk}) => ({
-            actName: act.name,
-            actLink: relation('linkFlash', chunk[0].thing),
-            dateFirst: +chunk[0].date,
-            dateLast: +chunk[chunk.length - 1].date,
-            entries:
-              chunk.map(entry =>
-                filterProperties(entry, [
-                  'contributionDescription',
-                  'flashLink',
-                ])),
-          }));
-
-      if (!empty(flashChunks)) {
-        const flashes = sections.flashes = {};
-        flashes.heading = relation('generateContentHeading');
-        flashes.chunks = flashChunks;
-      }
+    if (sprawl.enableFlashesAndGames && !empty(artist.flashesAsContributor)) {
+      const flashes = sections.flashes = {};
+      flashes.heading = relation('generateContentHeading');
+      flashes.list = relation('generateArtistInfoPageFlashesChunkedList', artist);
     }
-    */
 
     /*
     // Commentary doesn't use the detailed contribution system where multiple
@@ -414,7 +356,6 @@ export default {
             */
           ],
 
-          /*
           sec.flashes && [
             sec.flashes.heading
               .slots({
@@ -423,34 +364,8 @@ export default {
                 title: language.$('artistPage.flashList.title'),
               }),
 
-            html.tag('dl',
-              sec.flashes.chunks.map(({
-                actName,
-                actLink,
-                entries,
-                dateFirst,
-                dateLast,
-              }) => [
-                html.tag('dt',
-                  language.$('artistPage.creditList.flashAct.withDateRange', {
-                    act: actLink.slot('content', actName),
-                    dateRange: language.formatDateRange(dateFirst, dateLast),
-                  })),
-
-                html.tag('dd',
-                  html.tag('ul',
-                    entries
-                      .map(({flashLink, ...properties}) => ({
-                        ...properties,
-                        entry: language.$('artistPage.creditList.entry.flash', {
-                          flash: flashLink,
-                        }),
-                      }))
-                      .map(addAccentsToEntry)
-                      .map(row => html.tag('li', row)))),
-              ])),
+            sec.flashes.list,
           ],
-          */
 
           /*
           sec.commentary && [
diff --git a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js
index 2a8a2bbf..86548598 100644
--- a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js
@@ -140,10 +140,10 @@ export default {
           itemTrackLinks,
           itemOtherArtistLinks,
           itemTypes,
-          itemTrackRereleases,
           itemContributions,
         }) =>
           chunk.slots({
+            mode: 'album',
             albumLink,
             date,
 
diff --git a/src/content/dependencies/generateArtistInfoPageChunk.js b/src/content/dependencies/generateArtistInfoPageChunk.js
index 121cf43d..eb9056cb 100644
--- a/src/content/dependencies/generateArtistInfoPageChunk.js
+++ b/src/content/dependencies/generateArtistInfoPageChunk.js
@@ -2,9 +2,17 @@ export default {
   extraDependencies: ['html', 'language'],
 
   slots: {
+    mode: {
+      validate: v => v.is('flash', 'album'),
+    },
+
     albumLink: {type: 'html'},
+    flashActLink: {type: 'html'},
 
     date: {validate: v => v.isDate},
+    dateRangeStart: {validate: v => v.isDate},
+    dateRangeEnd: {validate: v => v.isDate},
+
     duration: {validate: v => v.isDuration},
     durationApproximate: {type: 'boolean'},
 
@@ -12,26 +20,55 @@ export default {
   },
 
   generate(slots, {html, language}) {
-    let accentedLink = slots.albumLink;
+    let accentedLink;
 
     accent: {
-      const options = {album: accentedLink};
-      const parts = ['artistPage.creditList.album'];
+      switch (slots.mode) {
+        case 'album': {
+          accentedLink = slots.albumLink;
 
-      if (slots.date) {
-        parts.push('withDate');
-        options.date = language.formatDate(slots.date);
-      }
+          const options = {album: accentedLink};
+          const parts = ['artistPage.creditList.album'];
 
-      if (slots.duration) {
-        parts.push('withDuration');
-        options.duration =
-          language.formatDuration(slots.duration, {
-            approximate: slots.durationApproximate,
-          });
-      }
+          if (slots.date) {
+            parts.push('withDate');
+            options.date = language.formatDate(slots.date);
+          }
+
+          if (slots.duration) {
+            parts.push('withDuration');
+            options.duration =
+              language.formatDuration(slots.duration, {
+                approximate: slots.durationApproximate,
+              });
+          }
 
-      accentedLink = language.formatString(parts.join('.'), options);
+          accentedLink = language.formatString(parts.join('.'), options);
+          break;
+        }
+
+        case 'flash': {
+          accentedLink = slots.flashActLink;
+
+          const options = {act: accentedLink};
+          const parts = ['artistPage.creditList.flashAct'];
+
+          if (
+            slots.dateRangeStart &&
+            slots.dateRangeEnd &&
+            slots.dateRangeStart !== slots.dateRangeEnd
+          ) {
+            parts.push('withDateRange');
+            options.dateRange = language.formatDateRange(slots.dateRangeStart, slots.dateRangeEnd);
+          } else if (slots.dateRangeStart || slots.date) {
+            parts.push('withDate');
+            options.date = language.formatDate(slots.dateFirst);
+          }
+
+          accentedLink = language.formatString(parts.join('.'), options);
+          break;
+        }
+      }
     }
 
     return html.tags([
diff --git a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
new file mode 100644
index 00000000..2f64483a
--- /dev/null
+++ b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
@@ -0,0 +1,134 @@
+import {stitchArrays} from '../../util/sugar.js';
+
+import {
+  chunkByProperties,
+  sortEntryThingPairs,
+  sortFlashesChronologically,
+} from '../../util/wiki-data.js';
+
+export default {
+  contentDependencies: [
+    'generateArtistInfoPageChunk',
+    'generateArtistInfoPageChunkItem',
+    'linkFlash',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  query(artist) {
+    const entries = [
+      ...artist.flashesAsContributor.map(flash => ({
+        thing: flash,
+        entry: {
+          flash,
+          act: flash.act,
+          contribs: flash.contributorContribs,
+        },
+      })),
+    ];
+
+    sortEntryThingPairs(entries, sortFlashesChronologically);
+
+    const chunks =
+      chunkByProperties(
+        entries.map(({entry}) => entry),
+        ['act']);
+
+    return {chunks};
+  },
+
+  relations(relation, query) {
+    // Flashes and games can list multiple contributors as collaborative
+    // credits, but we don't display these on the artist page, since they
+    // usually involve many artists crediting a larger team where collaboration
+    // isn't as relevant (without more particular details that aren't tracked
+    // on the wiki).
+
+    return {
+      chunks:
+        query.chunks.map(() => relation('generateArtistInfoPageChunk')),
+
+      actLinks:
+        query.chunks.map(({chunk}) =>
+          relation('linkFlash', chunk[0].flash)),
+
+      items:
+        query.chunks.map(({chunk}) =>
+          chunk.map(() => relation('generateArtistInfoPageChunkItem'))),
+
+      itemFlashLinks:
+        query.chunks.map(({chunk}) =>
+          chunk.map(({flash}) => relation('linkFlash', flash))),
+    };
+  },
+
+  data(query, artist) {
+    return {
+      actNames:
+        query.chunks.map(({act}) => act.name),
+
+      firstDates:
+        query.chunks.map(({chunk}) => chunk[0].flash.date ?? null),
+
+      lastDates:
+        query.chunks.map(({chunk}) => chunk[chunk.length - 1].flash.date ?? null),
+
+      itemContributions:
+        query.chunks.map(({chunk}) =>
+          chunk.map(({contribs}) =>
+            contribs
+              .find(({who}) => who === artist)
+              .what)),
+    };
+  },
+
+  generate(data, relations, {html, language}) {
+    return html.tag('dl',
+      stitchArrays({
+        chunk: relations.chunks,
+        actLink: relations.actLinks,
+        actName: data.actNames,
+        firstDate: data.firstDates,
+        lastDate: data.lastDates,
+
+        items: relations.items,
+        itemFlashLinks: relations.itemFlashLinks,
+        itemContributions: data.itemContributions,
+      }).map(({
+          chunk,
+          actLink,
+          actName,
+          firstDate,
+          lastDate,
+
+          items,
+          itemFlashLinks,
+          itemContributions,
+        }) =>
+          chunk.slots({
+            mode: 'flash',
+            flashActLink: actLink.slot('content', actName),
+            dateRangeStart: firstDate,
+            dateRangeEnd: lastDate,
+
+            items:
+              stitchArrays({
+                item: items,
+                flashLink: itemFlashLinks,
+                contribution: itemContributions,
+              }).map(({
+                  item,
+                  flashLink,
+                  contribution,
+                }) =>
+                  item.slots({
+                    contribution,
+
+                    content:
+                      language.$('artistPage.creditList.entry.flash', {
+                        flash: flashLink,
+                      }),
+                  })),
+          })));
+  },
+};
diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
index 0132d7ba..4dd4d468 100644
--- a/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageTracksChunkedList.js
@@ -137,6 +137,7 @@ export default {
           trackRereleases,
         }) =>
           chunk.slots({
+            mode: 'album',
             albumLink,
             date,
             duration,