diff options
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 |
commit | 1be8ada330ca2d49eb1681a23a7b0f8a8145c49a (patch) | |
tree | 97f2cdae5bc691fb3d268c2fdc47575714b4e042 /src | |
parent | 7800305ad381c0eaf417743aa2759f51cabc3919 (diff) |
yaml: flattenThingLayoutToDocumentOrder
Diffstat (limited to 'src')
-rw-r--r-- | src/data/yaml.js | 38 |
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 = ''; |