« get me outta code hell

content, upd8, yaml: adapt to combined artistData - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-30 10:52:20 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-30 14:30:05 -0400
commit7fbc5b87ed05bce433ed959ca18119b72835ee41 (patch)
treea9b96e8e575a927ed2e4a7a16036fce88b9a4a1d /src
parentf12bbec38694c30a79655a0be54768cd83f1efb5 (diff)
content, upd8, yaml: adapt to combined artistData
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/listArtistsByCommentaryEntries.js5
-rw-r--r--src/content/dependencies/listArtistsByContributions.js8
-rw-r--r--src/content/dependencies/listArtistsByDuration.js16
-rw-r--r--src/content/dependencies/listArtistsByGroup.js8
-rw-r--r--src/content/dependencies/listArtistsByLatestContribution.js3
-rw-r--r--src/content/dependencies/listArtistsByName.js3
-rw-r--r--src/data/yaml.js28
-rw-r--r--src/page/artist-alias.js2
-rw-r--r--src/page/artist.js2
-rwxr-xr-xsrc/upd8.js20
-rw-r--r--src/write/common-templates.js2
11 files changed, 60 insertions, 37 deletions
diff --git a/src/content/dependencies/listArtistsByCommentaryEntries.js b/src/content/dependencies/listArtistsByCommentaryEntries.js
index 4db9885e..aac3cfd1 100644
--- a/src/content/dependencies/listArtistsByCommentaryEntries.js
+++ b/src/content/dependencies/listArtistsByCommentaryEntries.js
@@ -10,7 +10,10 @@ export default {
   },
 
   query({artistData}, spec) {
-    const artists = sortAlphabetically(artistData.slice());
+    const artists =
+      sortAlphabetically(
+        artistData.filter(artist => !artist.isAlias));
+
     const counts =
       artists.map(artist =>
         artist.tracksAsCommentator.length +
diff --git a/src/content/dependencies/listArtistsByContributions.js b/src/content/dependencies/listArtistsByContributions.js
index 58c51a40..234c7edd 100644
--- a/src/content/dependencies/listArtistsByContributions.js
+++ b/src/content/dependencies/listArtistsByContributions.js
@@ -25,8 +25,12 @@ export default {
     };
 
     const queryContributionInfo = (artistsKey, countsKey, fn) => {
-      const artists = sortAlphabetically(sprawl.artistData.slice());
-      const counts = artists.map(artist => fn(artist));
+      const artists =
+        sortAlphabetically(
+          sprawl.artistData.filter(artist => !artist.isAlias));
+
+      const counts =
+        artists.map(artist => fn(artist));
 
       filterByCount(artists, counts);
       sortByCount(artists, counts, {greatestFirst: true});
diff --git a/src/content/dependencies/listArtistsByDuration.js b/src/content/dependencies/listArtistsByDuration.js
index d6a18978..056b126c 100644
--- a/src/content/dependencies/listArtistsByDuration.js
+++ b/src/content/dependencies/listArtistsByDuration.js
@@ -10,12 +10,16 @@ export default {
   },
 
   query({artistData}, spec) {
-    const artists = sortAlphabetically(artistData.slice());
-    const durations = artists.map(artist =>
-      getTotalDuration([
-        ...(artist.tracksAsArtist ?? []),
-        ...(artist.tracksAsContributor ?? []),
-      ], {originalReleasesOnly: true}));
+    const artists =
+      sortAlphabetically(
+        artistData.filter(artist => !artist.isAlias));
+
+    const durations =
+      artists.map(artist =>
+        getTotalDuration([
+          ...(artist.tracksAsArtist ?? []),
+          ...(artist.tracksAsContributor ?? []),
+        ], {originalReleasesOnly: true}));
 
     filterByCount(artists, durations);
     sortByCount(artists, durations, {greatestFirst: true});
diff --git a/src/content/dependencies/listArtistsByGroup.js b/src/content/dependencies/listArtistsByGroup.js
index 3778b9e3..69f910c7 100644
--- a/src/content/dependencies/listArtistsByGroup.js
+++ b/src/content/dependencies/listArtistsByGroup.js
@@ -15,8 +15,12 @@ export default {
   },
 
   query(sprawl, spec) {
-    const artists = sortAlphabetically(sprawl.artistData.slice());
-    const groups = sprawl.wikiInfo.divideTrackListsByGroups;
+    const artists =
+      sortAlphabetically(
+        sprawl.artistData.filter(artist => !artist.isAlias));
+
+    const groups =
+      sprawl.wikiInfo.divideTrackListsByGroups;
 
     if (empty(groups)) {
       return {spec, artists};
diff --git a/src/content/dependencies/listArtistsByLatestContribution.js b/src/content/dependencies/listArtistsByLatestContribution.js
index 45f8390f..03c51699 100644
--- a/src/content/dependencies/listArtistsByLatestContribution.js
+++ b/src/content/dependencies/listArtistsByLatestContribution.js
@@ -145,7 +145,8 @@ export default {
     //
 
     const artistsAlphabetically =
-      sortAlphabetically(sprawl.artistData.slice());
+      sortAlphabetically(
+        sprawl.artistData.filter(artist => !artist.isAlias));
 
     const artists =
       Array.from(artistLatestContribMap.keys());
diff --git a/src/content/dependencies/listArtistsByName.js b/src/content/dependencies/listArtistsByName.js
index 554b4587..7704e97b 100644
--- a/src/content/dependencies/listArtistsByName.js
+++ b/src/content/dependencies/listArtistsByName.js
@@ -12,7 +12,8 @@ export default {
     spec,
 
     artists:
-      sortAlphabetically(sprawl.artistData.slice()),
+      sortAlphabetically(
+        sprawl.artistData.filter(artist => !artist.isAlias)),
   }),
 
   relations: (relation, query) => ({
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 0f7f06f0..795eddf1 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -1118,8 +1118,22 @@ export function filterReferenceErrors(wikiData) {
     return recursive(obj, keys);
   }
 
-  const aggregate = openAggregate({message: `Errors validating between-thing references in data`});
   const boundFind = bindFind(wikiData, {mode: 'error'});
+
+  const artistAliasData = wikiData.artistData.filter(artist => artist.isAlias);
+  const findArtistOrAlias = artistRef => {
+    const alias = find.artistIncludingAliases(artistRef, artistAliasData, {mode: 'quiet'});
+    if (alias) {
+      // No need to check if the original exists here. Aliases are automatically
+      // created from a field on the original, so the original certainly exists.
+      const original = alias.aliasedArtist;
+      throw new Error(`Reference ${colors.red(artistRef)} is to an alias, should be ${colors.green(original.name)}`);
+    }
+
+    return boundFind.artist(artistRef);
+  };
+
+  const aggregate = openAggregate({message: `Errors validating between-thing references in data`});
   for (const [thingDataProp, propSpec] of referenceSpec) {
     const thingData = getNestedProp(wikiData, thingDataProp);
 
@@ -1165,18 +1179,6 @@ export function filterReferenceErrors(wikiData) {
 
             let findFn;
 
-            const findArtistOrAlias = artistRef => {
-              const alias = find.artist(artistRef, wikiData.artistAliasData, {mode: 'quiet'});
-              if (alias) {
-                // No need to check if the original exists here. Aliases are automatically
-                // created from a field on the original, so the original certainly exists.
-                const original = alias.aliasedArtist;
-                throw new Error(`Reference ${colors.red(artistRef)} is to an alias, should be ${colors.green(original.name)}`);
-              }
-
-              return boundFind.artist(artistRef);
-            };
-
             switch (findFnKey) {
               case '_artTag':
                 findFn = boundFind.artTag;
diff --git a/src/page/artist-alias.js b/src/page/artist-alias.js
index d2305229..c1177798 100644
--- a/src/page/artist-alias.js
+++ b/src/page/artist-alias.js
@@ -1,7 +1,7 @@
 export const description = `redirects for aliased artist names`;
 
 export function targets({wikiData}) {
-  return wikiData.artistAliasData;
+  return wikiData.artistData.filter(artist => artist.isAlias);
 }
 
 export function pathsForTarget(aliasArtist) {
diff --git a/src/page/artist.js b/src/page/artist.js
index b9a2f739..c1543fab 100644
--- a/src/page/artist.js
+++ b/src/page/artist.js
@@ -6,7 +6,7 @@ export const description = `per-artist info & artwork gallery pages`;
 
 // NB: See artist-alias.js for artist alias redirect pages.
 export function targets({wikiData}) {
-  return wikiData.artistData;
+  return wikiData.artistData.filter(artist => !artist.isAlias);
 }
 
 export function pathsForTarget(artist) {
diff --git a/src/upd8.js b/src/upd8.js
index eaf6b435..af3d107f 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -952,13 +952,20 @@ async function main() {
   Object.assign(wikiData, wikiDataResult);
 
   {
-    const logThings = (thingDataProp, label) =>
-      logInfo` - ${wikiData[thingDataProp]?.length ?? colors.red('(Missing!)')} ${colors.normal(colors.dim(label))}`;
+    const logThings = (prop, label) => {
+      const array =
+        (Array.isArray(prop)
+          ? prop
+          : wikiData[prop]);
+
+      logInfo` - ${array?.length ?? colors.red('(Missing!)')} ${colors.normal(colors.dim(label))}`;
+    }
+
     try {
       logInfo`Loaded data and processed objects:`;
       logThings('albumData', 'albums');
       logThings('trackData', 'tracks');
-      logThings('artistData', 'artists');
+      logThings(wikiData.artistData.filter(artist => !artist.isAlias), 'artists');
       if (wikiData.flashData) {
         logThings('flashData', 'flashes');
         logThings('flashActData', 'flash acts');
@@ -1050,7 +1057,7 @@ async function main() {
         // Needed for sorting
         'date', 'tracks',
         // Needed for computing page paths
-        'commentary', 'coverArtistContribs',
+        'aliasedArtist', 'commentary', 'coverArtistContribs',
       ]),
 
       artTagData: new Set([
@@ -1058,11 +1065,6 @@ async function main() {
         'isContentWarning',
       ]),
 
-      artistAliasData: new Set([
-        // Needed for computing page paths
-        'aliasedArtist',
-      ]),
-
       flashData: new Set([
         // Needed for sorting
         'act', 'date',
diff --git a/src/write/common-templates.js b/src/write/common-templates.js
index d897a73b..c9824a48 100644
--- a/src/write/common-templates.js
+++ b/src/write/common-templates.js
@@ -46,10 +46,12 @@ export function generateRandomLinkDataJSON({wikiData}) {
 
     artistDirectories:
       artistData
+        .filter(artist => !artist.isAlias)
         .map(artist => artist.directory),
 
     artistNumContributions:
       artistData
+        .filter(artist => !artist.isAlias)
         .map(artist => getArtistNumContributions(artist)),
   });
 }