« 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/dependencies/listArtistsByName.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/listArtistsByName.js')
-rw-r--r--src/content/dependencies/listArtistsByName.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/content/dependencies/listArtistsByName.js b/src/content/dependencies/listArtistsByName.js
new file mode 100644
index 0000000..9321849
--- /dev/null
+++ b/src/content/dependencies/listArtistsByName.js
@@ -0,0 +1,48 @@
+import {sortAlphabetically} from '#sort';
+import {stitchArrays} from '#sugar';
+import {getArtistNumContributions} from '#wiki-data';
+
+export default {
+  contentDependencies: ['generateListingPage', 'linkArtist', 'linkGroup'],
+  extraDependencies: ['language', 'wikiData'],
+
+  sprawl: ({artistData, wikiInfo}) =>
+    ({artistData, wikiInfo}),
+
+  query: (sprawl, spec) => ({
+    spec,
+
+    artists:
+      sortAlphabetically(
+        sprawl.artistData.filter(artist => !artist.isAlias)),
+  }),
+
+  relations: (relation, query) => ({
+    page:
+      relation('generateListingPage', query.spec),
+
+    artistLinks:
+      query.artists
+        .map(artist => relation('linkArtist', artist)),
+  }),
+
+  data: (query) => ({
+    counts:
+      query.artists
+        .map(artist => getArtistNumContributions(artist)),
+  }),
+
+  generate(data, relations, {language}) {
+    return relations.page.slots({
+      type: 'rows',
+      rows:
+        stitchArrays({
+          link: relations.artistLinks,
+          count: data.counts,
+        }).map(({link, count}) => ({
+            artist: link,
+            contributions: language.countContributions(count, {unit: true}),
+          })),
+    });
+  },
+};