« get me outta code hell

data, yaml: store data step info on Thing constructors - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/static-page.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-29 08:10:30 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-30 07:59:40 -0400
commiteb8b316bb9af7d34720de1fa8f8dbd4b81513b32 (patch)
tree22d435e702b89344304928b7a860a5326357f192 /src/data/things/static-page.js
parentb30585187480a270826767eaf97e1acc66126072 (diff)
data, yaml: store data step info on Thing constructors
Diffstat (limited to 'src/data/things/static-page.js')
-rw-r--r--src/data/things/static-page.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/data/things/static-page.js b/src/data/things/static-page.js
index 2da7312..1e8cb7c 100644
--- a/src/data/things/static-page.js
+++ b/src/data/things/static-page.js
@@ -1,5 +1,11 @@
+export const DATA_STATIC_PAGE_DIRECTORY = 'static-page';
+
+import * as path from 'node:path';
+
+import {traverse} from '#node-utils';
 import Thing from '#thing';
 import {isName} from '#validators';
+import {sortAlphabetically} from '#wiki-data';
 
 import {contentString, directory, name, simpleString}
   from '#composite/wiki-properties';
@@ -42,4 +48,26 @@ export class StaticPage extends Thing {
       'Review Points': {ignore: true},
     },
   };
+
+  static [Thing.getYamlLoadingSpec] = ({
+    documentModes: {onePerFile},
+    thingConstructors: {StaticPage},
+  }) => ({
+    title: `Process static page files`,
+
+    files: dataPath =>
+      traverse(path.join(dataPath, DATA_STATIC_PAGE_DIRECTORY), {
+        filterFile: name => path.extname(name) === '.yaml',
+        prefixPath: DATA_STATIC_PAGE_DIRECTORY,
+      }),
+
+    documentMode: onePerFile,
+    documentThing: StaticPage,
+
+    save(staticPageData) {
+      sortAlphabetically(staticPageData);
+
+      return {staticPageData};
+    },
+  });
 }