From fbf452ff1283b79ab5c4428ca6ccb13713ae9107 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 30 Jan 2024 11:20:16 -0400 Subject: find: avoid unhelpful duplicate directories in artist aliases --- src/find.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) 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({ -- cgit 1.3.0-6-gf8a5