diff options
Diffstat (limited to 'src/data')
-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 = ''; |