« get me outta code hell

content: generateArtistInfoPage: commentary section - 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-02 20:42:44 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-02 20:42:44 -0300
commit0213554fbd0d294df9093dc37697384d44488b49 (patch)
treebffeb5404171b7363f707b1c4e67362d4a60c832 /src/content/dependencies
parentf91ba586cafe13c7a137e30ac4d73f58b0731dc2 (diff)
content: generateArtistInfoPage: commentary section
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateArtistInfoPage.js158
1 files changed, 71 insertions, 87 deletions
diff --git a/src/content/dependencies/generateArtistInfoPage.js b/src/content/dependencies/generateArtistInfoPage.js
index b2b6f8b4..d5dc0240 100644
--- a/src/content/dependencies/generateArtistInfoPage.js
+++ b/src/content/dependencies/generateArtistInfoPage.js
@@ -129,29 +129,54 @@ export default {
         .map(({album, date, chunk}) => ({
           albumLink: relation('linkAlbum', album),
           date: +date,
-          entries: chunk.map(entry =>
-            filterProperties(entry, [
-              'contributionDescriptions',
-              'kind',
-              'otherArtistLinks',
-              'rerelease',
-              'trackLink',
-            ]))
+          entries:
+            chunk.map(entry =>
+              filterProperties(entry, [
+                'contributionDescriptions',
+                'kind',
+                'otherArtistLinks',
+                'rerelease',
+                'trackLink',
+              ])),
         }));
 
-    /*
-    const commentaryThings = sortAlbumsTracksChronologically([
-      ...(artist.albumsAsCommentator ?? []),
-      ...(artist.tracksAsCommentator ?? []),
-    ]);
+    // 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 commentaryListChunks = chunkByProperties(
-      commentaryThings.map((thing) => ({
-        album: thing.album || thing,
-        track: thing.album ? thing : null,
+    const commentaryEntries = [
+      ...artist.albumsAsCommentator.map(album => ({
+        kind: 'albumCommentary',
+        date: album.date,
+        thing: album,
+        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.
+    relations.commentaryChunks =
+      chunkByProperties(commentaryEntries, ['album', 'date'])
+        .map(({album, date, chunk}) => ({
+          albumLink: relation('linkAlbum', album),
+          date: +date,
+          entries:
+            chunk.map(entry =>
+              filterProperties(entry, [
+                'kind',
+                'trackLink',
+              ])),
+        }));
 
     return relations;
   },
@@ -260,6 +285,32 @@ export default {
                       .map(entry => html.tag('li', entry)))),
               ])),
           ],
+
+          !empty(relations.commentaryChunks) && [
+            html.tag('h2',
+              {id: 'commentary', class: ['content-heading']},
+              language.$('artistPage.commentaryList.title')),
+
+            html.tag('dl',
+              relations.commentaryChunks.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)))),
+              ])),
+          ],
         ],
 
         navLinkStyle: 'hierarchical',
@@ -280,29 +331,6 @@ export function write(artist, {wikiData}) {
 
   const {name, urls, contextNotes} = artist;
 
-  const artThingsAll = sortAlbumsTracksChronologically(
-    unique([
-      ...(artist.albumsAsCoverArtist ?? []),
-      ...(artist.albumsAsWallpaperArtist ?? []),
-      ...(artist.albumsAsBannerArtist ?? []),
-      ...(artist.tracksAsCoverArtist ?? []),
-    ]),
-    {getDate: (o) => o.coverArtDate});
-
-  const artThingsGallery = sortAlbumsTracksChronologically(
-    [
-      ...(artist.albumsAsCoverArtist ?? []),
-      ...(artist.tracksAsCoverArtist ?? []),
-    ],
-    {getDate: (o) => o.coverArtDate});
-
-  const commentaryThings = sortAlbumsTracksChronologically([
-    ...(artist.albumsAsCommentator ?? []),
-    ...(artist.tracksAsCommentator ?? []),
-  ]);
-
-  const hasGallery = !empty(artThingsGallery);
-
   const getArtistsAndContrib = (thing, key) => ({
     artists: thing[key]?.filter(({who}) => who !== artist),
     contrib: thing[key]?.find(({who}) => who === artist),
@@ -310,26 +338,6 @@ export function write(artist, {wikiData}) {
     key,
   });
 
-  const artListChunks = chunkByProperties(
-    artThingsAll.flatMap((thing) =>
-      ['coverArtistContribs', 'wallpaperArtistContribs', 'bannerArtistContribs']
-        .map((key) => getArtistsAndContrib(thing, key))
-        .filter(({contrib}) => contrib)
-        .map((props) => ({
-          album: thing.album || thing,
-          track: thing.album ? thing : null,
-          date: thing.date,
-          ...props,
-        }))),
-    ['date', 'album']);
-
-  const commentaryListChunks = chunkByProperties(
-    commentaryThings.map((thing) => ({
-      album: thing.album || thing,
-      track: thing.album ? thing : null,
-    })),
-    ['album']);
-
   const allTracks = sortAlbumsTracksChronologically(
     unique([
       ...(artist.tracksAsArtist ?? []),
@@ -707,31 +715,7 @@ export function write(artist, {wikiData}) {
                   ])),
               ]),
 
-            ...html.fragment(
-              !empty(commentaryThings) && [
-                html.tag('h2',
-                  {id: 'commentary', class: ['content-heading']},
-                  language.$('artistPage.commentaryList.title')),
-
-                html.tag('dl',
-                  commentaryListChunks.flatMap(({album, chunk}) => [
-                    html.tag('dt',
-                      language.$('artistPage.creditList.album', {
-                        album: link.album(album),
-                      })),
-
-                    html.tag('dd',
-                      html.tag('ul',
-                        chunk
-                          .map(({track}) => track
-                            ? language.$('artistPage.creditList.entry.track', {
-                                track: link.track(track),
-                              })
-                            : html.tag('i',
-                                language.$('artistPage.creditList.entry.album.commentary')))
-                          .map(row => html.tag('li', row)))),
-                  ])),
-              ]),
+            <commentary>
           ],
         },