« get me outta code hell

find, data: redirection overrides, use nameForReferencingAcrossWiki - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/find.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-06-05 11:30:06 -0300
committer(quasar) nebula <qznebula@protonmail.com>2026-06-05 11:30:06 -0300
commit0b39ab1a265070e6498939d0a08191946af6af81 (patch)
treecd5b986536501a88fafc32eabc6ed96c651ac9e0 /src/find.js
parent6c563804c1c327afb3dc56b16f50bba14d9d0882 (diff)
find, data: redirection overrides, use nameForReferencingAcrossWiki preview
Diffstat (limited to 'src/find.js')
-rw-r--r--src/find.js40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/find.js b/src/find.js
index ddd6ae05..6436532a 100644
--- a/src/find.js
+++ b/src/find.js
@@ -58,13 +58,25 @@ export function fuzzName(name, fuzz = {}) {
   return name;
 }
 
+export function nativeGetMatchableNames(thing, _nativeGetMatchableNames) {
+  if (thing.nameForReferencingAcrossWiki === null) {
+    return [];
+  }
+
+  if (thing.nameForReferencingAcrossWiki) {
+    return [thing.nameForReferencingAcrossWiki];
+  }
+
+  if (thing.name) {
+    return [thing.name];
+  }
+
+  return [];
+}
+
 export function processAvailableMatchesByName(data, fuzz, {
   include = _thing => true,
-
-  getMatchableNames = thing =>
-    (thing.constructor.hasPropertyDescriptor('name')
-      ? [thing.name]
-      : []),
+  getMatchableNames = nativeGetMatchableNames,
 
   results = Object.create(null),
   multipleNameMatches = Object.create(null),
@@ -72,7 +84,7 @@ export function processAvailableMatchesByName(data, fuzz, {
   for (const thing of data) {
     if (!include(thing)) continue;
 
-    for (const name of getMatchableNames(thing)) {
+    for (const name of getMatchableNames(thing, nativeGetMatchableNames)) {
       if (typeof name !== 'string') {
         logWarn`Unexpected ${typeAppearance(name)} returned in names for ${inspect(thing)}`;
         continue;
@@ -99,20 +111,24 @@ export function processAvailableMatchesByName(data, fuzz, {
   return {results, multipleNameMatches};
 }
 
+export function nativeGetMatchableDirectories(thing, _nativeGetMatchableDirectories) {
+  if (thing.directory) {
+    return [thing.directory];
+  } else {
+    return [];
+  }
+}
+
 export function processAvailableMatchesByDirectory(data, {
   include = _thing => true,
-
-  getMatchableDirectories = thing =>
-    (thing.constructor.hasPropertyDescriptor('directory')
-      ? [thing.directory]
-      : [null]),
+  getMatchableDirectories = nativeGetMatchableDirectories,
 
   results = Object.create(null),
 }) {
   for (const thing of data) {
     if (!include(thing, thingConstructors)) continue;
 
-    for (const directory of getMatchableDirectories(thing)) {
+    for (const directory of getMatchableDirectories(thing, nativeGetMatchableDirectories)) {
       if (typeof directory !== 'string') {
         logWarn`Unexpected ${typeAppearance(directory)} returned in directories for ${inspect(thing)}`;
         continue;