From 2960fb60606ce0e356f7cb62c3b17e9d41e742fc Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 29 Jan 2024 08:22:53 -0400 Subject: data, yaml: store sorting info on getYamlLoadingSpec --- src/data/yaml.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/data/yaml.js') 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 -- cgit 1.3.0-6-gf8a5