From 1be8ada330ca2d49eb1681a23a7b0f8a8145c49a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 22 Feb 2025 14:57:32 -0400 Subject: yaml: flattenThingLayoutToDocumentOrder --- src/data/yaml.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/data') 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 = ''; -- cgit 1.3.0-6-gf8a5