« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content/dependencies/listArtistsByGroup.js133
-rw-r--r--src/content/dependencies/listArtistsByName.js151
-rw-r--r--src/listing-spec.js10
-rw-r--r--src/strings-default.json7
4 files changed, 180 insertions, 121 deletions
diff --git a/src/content/dependencies/listArtistsByGroup.js b/src/content/dependencies/listArtistsByGroup.js
new file mode 100644
index 00000000..3778b9e3
--- /dev/null
+++ b/src/content/dependencies/listArtistsByGroup.js
@@ -0,0 +1,133 @@
+import {empty, stitchArrays, unique} from '#sugar';
+
+import {
+  filterMultipleArrays,
+  getArtistNumContributions,
+  sortAlphabetically,
+} from '#wiki-data';
+
+export default {
+  contentDependencies: ['generateListingPage', 'linkArtist', 'linkGroup'],
+  extraDependencies: ['language', 'wikiData'],
+
+  sprawl({artistData, wikiInfo}) {
+    return {artistData, wikiInfo};
+  },
+
+  query(sprawl, spec) {
+    const artists = sortAlphabetically(sprawl.artistData.slice());
+    const groups = sprawl.wikiInfo.divideTrackListsByGroups;
+
+    if (empty(groups)) {
+      return {spec, artists};
+    }
+
+    const artistGroups =
+      artists.map(artist =>
+        unique(
+          unique([
+            ...artist.albumsAsAny,
+            ...artist.tracksAsAny.map(track => track.album),
+          ]).flatMap(album => album.groups)))
+
+    const artistsByGroup =
+      groups.map(group =>
+        artists.filter((artist, index) => artistGroups[index].includes(group)));
+
+    filterMultipleArrays(groups, artistsByGroup,
+      (group, artists) => !empty(artists));
+
+    return {spec, groups, artistsByGroup};
+  },
+
+  relations(relation, query) {
+    const relations = {};
+
+    relations.page =
+      relation('generateListingPage', query.spec);
+
+    if (query.artists) {
+      relations.artistLinks =
+        query.artists
+          .map(artist => relation('linkArtist', artist));
+    }
+
+    if (query.artistsByGroup) {
+      relations.groupLinks =
+        query.groups
+          .map(group => relation('linkGroup', group));
+
+      relations.artistLinksByGroup =
+        query.artistsByGroup
+          .map(artists => artists
+            .map(artist => relation('linkArtist', artist)));
+    }
+
+    return relations;
+  },
+
+  data(query) {
+    const data = {};
+
+    if (query.artists) {
+      data.counts =
+        query.artists
+          .map(artist => getArtistNumContributions(artist));
+    }
+
+    if (query.artistsByGroup) {
+      data.groupDirectories =
+        query.groups
+          .map(group => group.directory);
+
+      data.countsByGroup =
+        query.artistsByGroup
+          .map(artists => artists
+            .map(artist => getArtistNumContributions(artist)));
+    }
+
+    return data;
+  },
+
+  generate(data, relations, {language}) {
+    return (
+      (relations.artistLinksByGroup
+        ? relations.page.slots({
+            type: 'chunks',
+
+            showSkipToSection: true,
+            chunkIDs:
+              data.groupDirectories
+                .map(directory => `contributed-to-${directory}`),
+
+            chunkTitles:
+              relations.groupLinks.map(groupLink => ({
+                group: groupLink,
+              })),
+
+            chunkRows:
+              stitchArrays({
+                artistLinks: relations.artistLinksByGroup,
+                counts: data.countsByGroup,
+              }).map(({artistLinks, counts}) =>
+                  stitchArrays({
+                    link: artistLinks,
+                    count: counts,
+                  }).map(({link, count}) => ({
+                      artist: link,
+                      contributions: language.countContributions(count, {unit: true}),
+                    }))),
+          })
+        : relations.page.slots({
+            type: 'rows',
+            rows:
+              stitchArrays({
+                link: relations.artistLinks,
+                count: data.counts,
+              }).map(({link, count}) => ({
+                  artist: link,
+                  contributions: language.countContributions(count, {unit: true}),
+                })),
+          })));
+  },
+};
diff --git a/src/content/dependencies/listArtistsByName.js b/src/content/dependencies/listArtistsByName.js
index 3778b9e3..554b4587 100644
--- a/src/content/dependencies/listArtistsByName.js
+++ b/src/content/dependencies/listArtistsByName.js
@@ -1,133 +1,46 @@
-import {empty, stitchArrays, unique} from '#sugar';
-
-import {
-  filterMultipleArrays,
-  getArtistNumContributions,
-  sortAlphabetically,
-} from '#wiki-data';
+import {stitchArrays} from '#sugar';
+import {getArtistNumContributions, sortAlphabetically} from '#wiki-data';
 
 export default {
   contentDependencies: ['generateListingPage', 'linkArtist', 'linkGroup'],
   extraDependencies: ['language', 'wikiData'],
 
-  sprawl({artistData, wikiInfo}) {
-    return {artistData, wikiInfo};
-  },
-
-  query(sprawl, spec) {
-    const artists = sortAlphabetically(sprawl.artistData.slice());
-    const groups = sprawl.wikiInfo.divideTrackListsByGroups;
-
-    if (empty(groups)) {
-      return {spec, artists};
-    }
-
-    const artistGroups =
-      artists.map(artist =>
-        unique(
-          unique([
-            ...artist.albumsAsAny,
-            ...artist.tracksAsAny.map(track => track.album),
-          ]).flatMap(album => album.groups)))
-
-    const artistsByGroup =
-      groups.map(group =>
-        artists.filter((artist, index) => artistGroups[index].includes(group)));
-
-    filterMultipleArrays(groups, artistsByGroup,
-      (group, artists) => !empty(artists));
-
-    return {spec, groups, artistsByGroup};
-  },
-
-  relations(relation, query) {
-    const relations = {};
+  sprawl: ({artistData, wikiInfo}) =>
+    ({artistData, wikiInfo}),
 
-    relations.page =
-      relation('generateListingPage', query.spec);
+  query: (sprawl, spec) => ({
+    spec,
 
-    if (query.artists) {
-      relations.artistLinks =
-        query.artists
-          .map(artist => relation('linkArtist', artist));
-    }
+    artists:
+      sortAlphabetically(sprawl.artistData.slice()),
+  }),
 
-    if (query.artistsByGroup) {
-      relations.groupLinks =
-        query.groups
-          .map(group => relation('linkGroup', group));
+  relations: (relation, query) => ({
+    page:
+      relation('generateListingPage', query.spec),
 
-      relations.artistLinksByGroup =
-        query.artistsByGroup
-          .map(artists => artists
-            .map(artist => relation('linkArtist', artist)));
-    }
+    artistLinks:
+      query.artists
+        .map(artist => relation('linkArtist', artist)),
+  }),
 
-    return relations;
-  },
-
-  data(query) {
-    const data = {};
-
-    if (query.artists) {
-      data.counts =
-        query.artists
-          .map(artist => getArtistNumContributions(artist));
-    }
-
-    if (query.artistsByGroup) {
-      data.groupDirectories =
-        query.groups
-          .map(group => group.directory);
-
-      data.countsByGroup =
-        query.artistsByGroup
-          .map(artists => artists
-            .map(artist => getArtistNumContributions(artist)));
-    }
-
-    return data;
-  },
+  data: (query) => ({
+    counts:
+      query.artists
+        .map(artist => getArtistNumContributions(artist)),
+  }),
 
   generate(data, relations, {language}) {
-    return (
-      (relations.artistLinksByGroup
-        ? relations.page.slots({
-            type: 'chunks',
-
-            showSkipToSection: true,
-            chunkIDs:
-              data.groupDirectories
-                .map(directory => `contributed-to-${directory}`),
-
-            chunkTitles:
-              relations.groupLinks.map(groupLink => ({
-                group: groupLink,
-              })),
-
-            chunkRows:
-              stitchArrays({
-                artistLinks: relations.artistLinksByGroup,
-                counts: data.countsByGroup,
-              }).map(({artistLinks, counts}) =>
-                  stitchArrays({
-                    link: artistLinks,
-                    count: counts,
-                  }).map(({link, count}) => ({
-                      artist: link,
-                      contributions: language.countContributions(count, {unit: true}),
-                    }))),
-          })
-        : relations.page.slots({
-            type: 'rows',
-            rows:
-              stitchArrays({
-                link: relations.artistLinks,
-                count: data.counts,
-              }).map(({link, count}) => ({
-                  artist: link,
-                  contributions: language.countContributions(count, {unit: true}),
-                })),
-          })));
+    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}),
+          })),
+    });
   },
 };
diff --git a/src/listing-spec.js b/src/listing-spec.js
index fe36fc01..7918dd1e 100644
--- a/src/listing-spec.js
+++ b/src/listing-spec.js
@@ -54,12 +54,14 @@ listingSpec.push({
   directory: 'artists/by-name',
   stringsKey: 'listArtists.byName',
   contentFunction: 'listArtistsByName',
+  seeAlso: ['artists/by-contribs', 'artists/by-group'],
 });
 
 listingSpec.push({
   directory: 'artists/by-contribs',
   stringsKey: 'listArtists.byContribs',
   contentFunction: 'listArtistsByContributions',
+  seeAlso: ['artists/by-name', 'artists/by-group'],
 });
 
 listingSpec.push({
@@ -75,6 +77,14 @@ listingSpec.push({
 });
 
 listingSpec.push({
+  directory: 'artists/by-group',
+  stringsKey: 'listArtists.byGroup',
+  contentFunction: 'listArtistsByGroup',
+  featureFlag: 'enableGroupUI',
+  seeAlso: ['artists/by-name', 'artists/by-contribs'],
+});
+
+listingSpec.push({
   directory: 'artists/by-latest',
   stringsKey: 'listArtists.byLatest',
   contentFunction: 'listArtistsByLatestContribution',
diff --git a/src/strings-default.json b/src/strings-default.json
index 2cab3a19..457b4bed 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -368,8 +368,6 @@
   "listingPage.listArtists.byName.title": "Artists - by Name",
   "listingPage.listArtists.byName.title.short": "...by Name",
   "listingPage.listArtists.byName.item": "{ARTIST} ({CONTRIBUTIONS})",
-  "listingPage.listArtists.byName.chunk.title": "Contributed to {GROUP}:",
-  "listingPage.listArtists.byName.chunk.item": "{ARTIST} ({CONTRIBUTIONS})",
   "listingPage.listArtists.byContribs.title": "Artists - by Contributions",
   "listingPage.listArtists.byContribs.title.short": "...by Contributions",
   "listingPage.listArtists.byContribs.item": "{ARTIST} ({CONTRIBUTIONS})",
@@ -379,6 +377,11 @@
   "listingPage.listArtists.byDuration.title": "Artists - by Duration",
   "listingPage.listArtists.byDuration.title.short": "...by Duration",
   "listingPage.listArtists.byDuration.item": "{ARTIST} ({DURATION})",
+  "listingPage.listArtists.byGroup.title": "Artists - by Group",
+  "listingPage.listArtists.byGroup.title.short": "...by Group",
+  "listingPage.listArtists.byGroup.item": "{ARTIST} ({CONTRIBUTIONS})",
+  "listingPage.listArtists.byGroup.chunk.title": "Contributed to {GROUP}:",
+  "listingPage.listArtists.byGroup.chunk.item": "{ARTIST} ({CONTRIBUTIONS})",
   "listingPage.listArtists.byLatest.title": "Artists - by Latest Contribution",
   "listingPage.listArtists.byLatest.title.short": "...by Latest Contribution",
   "listingPage.listArtists.byLatest.chunk.title.album": "{ALBUM} ({DATE})",