« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 = '';