diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-29 08:22:53 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-30 07:59:40 -0400 |
commit | 2960fb60606ce0e356f7cb62c3b17e9d41e742fc (patch) | |
tree | 0976c8866912ed81d757a53c4315361cdf01aed6 /src/data/yaml.js | |
parent | eb8b316bb9af7d34720de1fa8f8dbd4b81513b32 (diff) |
data, yaml: store sorting info on getYamlLoadingSpec
Diffstat (limited to 'src/data/yaml.js')
-rw-r--r-- | src/data/yaml.js | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js index b0ec3c9c..342924e0 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -12,6 +12,7 @@ import {colors, ENABLE_COLOR, logInfo, logWarn} from '#cli'; import find, {bindFind} from '#find'; import Thing from '#thing'; import thingConstructors from '#things'; +import {commentaryRegex, sortByName} from '#wiki-data'; import { annotateErrorWithFile, @@ -29,14 +30,6 @@ import { withEntries, } from '#sugar'; -import { - commentaryRegex, - sortAlbumsTracksChronologically, - sortByName, - sortChronologically, - sortFlashesChronologically, -} from '#wiki-data'; - function inspect(value, opts = {}) { return nodeInspect(value, {colors: ENABLE_COLOR, ...opts}); } @@ -534,8 +527,8 @@ export const documentModes = { export const getDataSteps = () => { const steps = []; - for (const thing of Object.values(thingConstructors)) { - const getSpecFn = thing[Thing.getYamlLoadingSpec]; + for (const thingConstructor of Object.values(thingConstructors)) { + const getSpecFn = thingConstructor[Thing.getYamlLoadingSpec]; if (!getSpecFn) continue; steps.push(getSpecFn({ @@ -992,11 +985,17 @@ export function linkWikiDataArrays(wikiData) { } export function sortWikiDataArrays(wikiData) { - Object.assign(wikiData, { - albumData: sortChronologically(wikiData.albumData.slice()), - trackData: sortAlbumsTracksChronologically(wikiData.trackData.slice()), - flashData: sortFlashesChronologically(wikiData.flashData.slice()), - }); + for (const [key, value] of Object.entries(wikiData)) { + if (!Array.isArray(value)) continue; + wikiData[key] = value.slice(); + } + + const steps = getDataSteps(); + + for (const step of steps) { + if (!step.sort) continue; + step.sort(wikiData); + } // Re-link data arrays, so that every object has the new, sorted versions. // Note that the sorting step deliberately creates new arrays (mutating |