« get me outta code hell

data, yaml: store sorting info on getYamlLoadingSpec - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
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
commit2960fb60606ce0e356f7cb62c3b17e9d41e742fc (patch)
tree0976c8866912ed81d757a53c4315361cdf01aed6 /src
parenteb8b316bb9af7d34720de1fa8f8dbd4b81513b32 (diff)
data, yaml: store sorting info on getYamlLoadingSpec
Diffstat (limited to 'src')
-rw-r--r--src/data/things/album.js7
-rw-r--r--src/data/things/art-tag.js6
-rw-r--r--src/data/things/flash.js5
-rw-r--r--src/data/things/news-entry.js7
-rw-r--r--src/data/things/static-page.js6
-rw-r--r--src/data/yaml.js29
6 files changed, 35 insertions, 25 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 9d4729e4..318979cc 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -8,6 +8,8 @@ import {traverse} from '#node-utils';
 import {empty} from '#sugar';
 import Thing from '#thing';
 import {isDate} from '#validators';
+import {sortAlbumsTracksChronologically, sortChronologically}
+  from '#wiki-data';
 import {parseAdditionalFiles, parseContributors, parseDate, parseDimensions}
   from '#yaml';
 
@@ -369,6 +371,11 @@ export class Album extends Thing {
 
       return {albumData, trackData};
     },
+
+    sort({albumData, trackData}) {
+      sortChronologically(albumData);
+      sortAlbumsTracksChronologically(trackData);
+    },
   });
 }
 
diff --git a/src/data/things/art-tag.js b/src/data/things/art-tag.js
index 29cd2990..4d423db5 100644
--- a/src/data/things/art-tag.js
+++ b/src/data/things/art-tag.js
@@ -86,10 +86,10 @@ export class ArtTag extends Thing {
     documentMode: allInOne,
     documentThing: ArtTag,
 
-    save(artTagData) {
-      sortAlphabetically(artTagData);
+    save: (results) => ({artTagData: results}),
 
-      return {artTagData};
+    sort({artTagData}) {
+      sortAlphabetically(artTagData);
     },
   });
 }
diff --git a/src/data/things/flash.js b/src/data/things/flash.js
index ad80cbf2..93653548 100644
--- a/src/data/things/flash.js
+++ b/src/data/things/flash.js
@@ -4,6 +4,7 @@ import {input} from '#composite';
 import find from '#find';
 import Thing from '#thing';
 import {anyOf, isColor, isDirectory, isNumber, isString} from '#validators';
+import {sortFlashesChronologically} from '#wiki-data';
 import {parseDate, parseContributors} from '#yaml';
 
 import {exposeDependency, exposeUpdateValueOrContinue}
@@ -250,5 +251,9 @@ export class FlashAct extends Thing {
 
       return {flashData, flashActData};
     },
+
+    sort({flashData}) {
+      sortFlashesChronologically(flashData);
+    },
   });
 }
diff --git a/src/data/things/news-entry.js b/src/data/things/news-entry.js
index 658453b0..e0ec7f7b 100644
--- a/src/data/things/news-entry.js
+++ b/src/data/things/news-entry.js
@@ -57,11 +57,10 @@ export class NewsEntry extends Thing {
     documentMode: allInOne,
     documentThing: NewsEntry,
 
-    save(newsData) {
-      sortChronologically(newsData);
-      newsData.reverse();
+    save: (results) => ({newsData: results}),
 
-      return {newsData};
+    sort({newsData}) {
+      sortChronologically(newsData, {latestFirst: true});
     },
   });
 }
diff --git a/src/data/things/static-page.js b/src/data/things/static-page.js
index 1e8cb7c6..9c7fec65 100644
--- a/src/data/things/static-page.js
+++ b/src/data/things/static-page.js
@@ -64,10 +64,10 @@ export class StaticPage extends Thing {
     documentMode: onePerFile,
     documentThing: StaticPage,
 
-    save(staticPageData) {
-      sortAlphabetically(staticPageData);
+    save: (results) => ({staticPageData: results}),
 
-      return {staticPageData};
+    sort({staticPageData}) {
+      sortAlphabetically(staticPageData);
     },
   });
 }
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