« get me outta code hell

yaml: fix duplicate directory double-reporting (or more) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-30 08:18:43 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-30 14:30:00 -0400
commit7963d414a73f3031ff52d4076f8c2cfe68826150 (patch)
tree60f0f791d2cd8810554a66e4fdb069bc5871ffe5
parent78fa1765e28152b94062c43776b2de937d0ea08f (diff)
yaml: fix duplicate directory double-reporting (or more)
-rw-r--r--src/data/yaml.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 342924e0..e47da51c 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -1028,13 +1028,13 @@ export function filterDuplicateDirectories(wikiData) {
     const thingData = wikiData[thingDataProp];
     aggregate.nest({message: `Duplicate directories found in ${colors.green('wikiData.' + thingDataProp)}`}, ({call}) => {
       const directoryPlaces = Object.create(null);
-      const duplicateDirectories = [];
+      const duplicateDirectories = new Set();
 
       for (const thing of thingData) {
         const {directory} = thing;
         if (directory in directoryPlaces) {
           directoryPlaces[directory].push(thing);
-          duplicateDirectories.push(directory);
+          duplicateDirectories.add(directory);
         } else {
           directoryPlaces[directory] = [thing];
         }
@@ -1042,13 +1042,15 @@ export function filterDuplicateDirectories(wikiData) {
 
       if (empty(duplicateDirectories)) return;
 
-      duplicateDirectories.sort((a, b) => {
-        const aL = a.toLowerCase();
-        const bL = b.toLowerCase();
-        return aL < bL ? -1 : aL > bL ? 1 : 0;
-      });
+      const sortedDuplicateDirectories =
+        Array.from(duplicateDirectories)
+          .sort((a, b) => {
+            const aL = a.toLowerCase();
+            const bL = b.toLowerCase();
+            return aL < bL ? -1 : aL > bL ? 1 : 0;
+          });
 
-      for (const directory of duplicateDirectories) {
+      for (const directory of sortedDuplicateDirectories) {
         const places = directoryPlaces[directory];
         call(() => {
           throw new Error(