diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-30 11:20:16 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-30 14:30:05 -0400 |
commit | fbf452ff1283b79ab5c4428ca6ccb13713ae9107 (patch) | |
tree | 751a322d8413227dbdd460fde1e171572ba35293 /src | |
parent | 12a8b6d1148c7d616296c8ab4ed86cbc856e3861 (diff) |
find: avoid unhelpful duplicate directories in artist aliases
Diffstat (limited to 'src')
-rw-r--r-- | src/find.js | 45 |
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({ |