« 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/generateListingPage.js7
-rw-r--r--src/content/dependencies/listArtistsByContributions.js159
2 files changed, 165 insertions, 1 deletions
diff --git a/src/content/dependencies/generateListingPage.js b/src/content/dependencies/generateListingPage.js
index 93b35497..cab80a7f 100644
--- a/src/content/dependencies/generateListingPage.js
+++ b/src/content/dependencies/generateListingPage.js
@@ -58,12 +58,14 @@ export default {
   },
 
   slots: {
-    type: {validate: v => v.is('rows', 'chunks'),},
+    type: {validate: v => v.is('rows', 'chunks', 'custom')},
 
     rows: {validate: v => v.arrayOf(v.isObject)},
 
     chunkTitles: {validate: v => v.arrayOf(v.isObject)},
     chunkRows: {validate: v => v.arrayOf(v.isObject)},
+
+    content: {type: 'html'},
   },
 
   generate(data, relations, slots, {html, language}) {
@@ -122,6 +124,9 @@ export default {
                       html.tag('li',
                         language.$(`listingPage.${data.stringsKey}.chunk.item`, row))))),
               ])),
+
+        slots.type === 'custom' &&
+          slots.content,
       ],
 
       navLinkStyle: 'hierarchical',
diff --git a/src/content/dependencies/listArtistsByContributions.js b/src/content/dependencies/listArtistsByContributions.js
new file mode 100644
index 00000000..78c8c1aa
--- /dev/null
+++ b/src/content/dependencies/listArtistsByContributions.js
@@ -0,0 +1,159 @@
+import {stitchArrays, unique} from '../../util/sugar.js';
+
+export default {
+  contentDependencies: ['generateListingPage', 'linkArtist'],
+  extraDependencies: ['html', 'language', 'wikiData'],
+
+  sprawl({artistData, wikiInfo}) {
+    return {
+      artistData,
+      enableFlashesAndGames: wikiInfo.enableFlashesAndGames,
+    };
+  },
+
+  query(sprawl, spec) {
+    const query = {spec};
+
+    const queryContributionInfo = fn =>
+      sprawl.artistData
+        .map(artist => ({artist, contributions: fn(artist)}))
+        .filter(({contributions}) => contributions)
+        .sort((a, b) => b.contributions - a.contributions);
+
+    query.enableFlashesAndGames =
+      sprawl.enableFlashesAndGames;
+
+    query.trackContributionInfo =
+      queryContributionInfo(artist =>
+        unique([
+          ...artist.tracksAsContributor,
+          ...artist.tracksAsArtist,
+        ]).length);
+
+    query.artworkContributionInfo =
+      queryContributionInfo(artist =>
+        artist.tracksAsCoverArtist.length +
+        artist.albumsAsCoverArtist.length +
+        artist.albumsAsWallpaperArtist.length +
+        artist.albumsAsBannerArtist.length);
+
+    if (sprawl.enableFlashesAndGames) {
+      query.flashContributionInfo =
+        queryContributionInfo(artist =>
+          artist.flashesAsContributor.length);
+    }
+
+    return query;
+  },
+
+  relations(relation, query) {
+    const relations = {};
+
+    relations.page =
+      relation('generateListingPage', query.spec);
+
+    relations.artistLinksByTrackContributions =
+      query.trackContributionInfo
+        .map(({artist}) => relation('linkArtist', artist));
+
+    relations.artistLinksByArtworkContributions =
+      query.artworkContributionInfo
+        .map(({artist}) => relation('linkArtist', artist));
+
+    if (query.enableFlashesAndGames) {
+      relations.artistLinksByFlashContributions =
+        query.flashContributionInfo
+          .map(({artist}) => relation('linkArtist', artist));
+    }
+
+    return relations;
+  },
+
+  data(query) {
+    const data = {};
+
+    data.enableFlashesAndGames =
+      query.enableFlashesAndGames;
+
+    data.countsByTrackContributions =
+      query.trackContributionInfo
+        .map(({contributions}) => contributions);
+
+    data.countsByArtworkContributions =
+      query.artworkContributionInfo
+        .map(({contributions}) => contributions);
+
+    if (query.enableFlashesAndGames) {
+      data.countsByFlashContributions =
+        query.flashContributionInfo
+          .map(({contributions}) => contributions);
+    }
+
+    return data;
+  },
+
+  generate(data, relations, {html, language}) {
+    const lists = Object.fromEntries(
+      ([
+        ['tracks', [
+          relations.artistLinksByTrackContributions,
+          data.countsByTrackContributions,
+          'countTracks',
+        ]],
+
+        ['artworks', [
+          relations.artistLinksByArtworkContributions,
+          data.countsByArtworkContributions,
+          'countArtworks',
+        ]],
+
+        data.enableFlashesAndGames &&
+          ['flashes', [
+            relations.artistLinksByFlashContributions,
+            data.countsByFlashContributions,
+            'countFlashes',
+          ]],
+      ]).filter(Boolean)
+        .map(([key, [artistLinks, counts, countFunction]]) => [
+          key,
+          html.tag('ul',
+            stitchArrays({
+              artistLink: artistLinks,
+              count: counts,
+            }).map(({artistLink, count}) =>
+                html.tag('li',
+                  language.$('listingPage.listArtists.byContribs.item', {
+                    artist: artistLink,
+                    contributions: language[countFunction](count, {unit: true}),
+                  })))),
+        ]));
+
+    return relations.page.slots({
+      type: 'custom',
+      content:
+        html.tag('div', {class: 'content-columns'}, [
+          html.tag('div', {class: 'column'}, [
+            html.tag('h2',
+              language.$('listingPage.misc.trackContributors')),
+
+            lists.tracks,
+          ]),
+
+          html.tag('div', {class: 'column'}, [
+            html.tag('h2',
+              language.$(
+                'listingPage.misc.artContributors')),
+
+            lists.artworks,
+
+            lists.flashes && [
+              html.tag('h2',
+                language.$('listingPage.misc.artAndFlashContributors')),
+
+              lists.flashes,
+            ],
+          ]),
+        ]),
+    });
+  },
+};