« get me outta code hell

yaml: flattenThingLayoutToDocumentOrder - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/yaml.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-02-22 14:57:32 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-02-22 21:12:22 -0400
commit1be8ada330ca2d49eb1681a23a7b0f8a8145c49a (patch)
tree97f2cdae5bc691fb3d268c2fdc47575714b4e042 /src/data/yaml.js
parent7800305ad381c0eaf417743aa2759f51cabc3919 (diff)
yaml: flattenThingLayoutToDocumentOrder
Diffstat (limited to 'src/data/yaml.js')
-rw-r--r--src/data/yaml.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 4ad8bd8c..a5614ea6 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -1532,6 +1532,44 @@ export function getThingLayoutForFilename(filename, wikiData) {
   }
 }
 
+export function flattenThingLayoutToDocumentOrder(layout) {
+  switch (layout.documentMode) {
+    case documentModes.oneDocumentTotal:
+    case documentModes.onePerFile: {
+      if (layout.thing) {
+        return [0];
+      } else {
+        return [];
+      }
+    }
+
+    case documentModes.allInOne: {
+      const indices =
+        layout.things
+          .map(thing => thing[Thing.yamlSourceDocumentPlacement][1]);
+
+      return indices;
+    }
+
+    case documentModes.headerAndEntries: {
+      const entryIndices =
+        layout.entryThings
+          .map(thing => thing[Thing.yamlSourceDocumentPlacement][2])
+          .map(index => index + 1);
+
+      if (layout.headerThing) {
+        return [0, ...entryIndices];
+      } else {
+        return entryIndices;
+      }
+    }
+
+    default: {
+      throw new Error(`Unknown document mode`);
+    }
+  }
+}
+
 export function* splitDocumentsInYAMLSourceText(sourceText) {
   const dividerRegex = /^-{3,}\n?/gm;
   let previousDivider = '';