« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/find.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/find.js b/src/find.js
index 9ed084d7..fecf1ab0 100644
--- a/src/find.js
+++ b/src/find.js
@@ -3,6 +3,7 @@ import {inspect} from 'node:util';
 import CacheableObject from '#cacheable-object';
 import {colors, logWarn} from '#cli';
 import {typeAppearance} from '#sugar';
+import {getKebabCase} from '#wiki-data';
 
 function warnOrThrow(mode, message) {
   if (mode === 'error') {
@@ -161,6 +162,50 @@ const find = {
 
   artistIncludingAliases: findHelper({
     referenceTypes: ['artist', 'artist-gallery'],
+
+    getMatchableDirectories(artist) {
+      // Regular artists are always matchable by their directory.
+      if (!artist.isAlias) {
+        return [artist.directory];
+      }
+
+      const originalArtist = artist.aliasedArtist;
+
+      // Aliases never match by the same directory as the original.
+      if (artist.directory === originalArtist.directory) {
+        return [];
+      }
+
+      // Aliases never match by the same directory as some *previous* alias
+      // in the original's alias list. This is honestly a bit awkward, but it
+      // avoids artist aliases conflicting with each other when checking for
+      // duplicate directories.
+      for (const aliasName of originalArtist.aliasNames) {
+        // These are trouble. We should be accessing aliases' directories
+        // directly, but artists currently don't expose a reverse reference
+        // list for aliases. (This is pending a cleanup of "reverse reference"
+        // behavior in general.) It doesn't actually cause problems *here*
+        // because alias directories are computed from their names 100% of the
+        // time, but that *is* an assumption this code makes.
+        if (aliasName === artist.name) continue;
+        if (artist.directory === getKebabCase(aliasName)) {
+          return [];
+        }
+      }
+
+      // And, aliases never return just a blank string. This part is pretty
+      // spooky because it doesn't handle two differently named aliases, on
+      // different artists, who have names that are similar *apart* from a
+      // character that's shortened. But that's also so fundamentally scary
+      // that we can't support it properly with existing code, anyway - we
+      // would need to be able to specifically set a directory *on an alias,*
+      // which currently can't be done in YAML data files.
+      if (artist.directory === '') {
+        return [];
+      }
+
+      return [artist.directory];
+    },
   }),
 
   artTag: findHelper({