From eb8b316bb9af7d34720de1fa8f8dbd4b81513b32 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 29 Jan 2024 08:10:30 -0400 Subject: data, yaml: store data step info on Thing constructors --- src/data/things/homepage-layout.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/data/things/homepage-layout.js') diff --git a/src/data/things/homepage-layout.js b/src/data/things/homepage-layout.js index 38fd5a7a..00d6aef5 100644 --- a/src/data/things/homepage-layout.js +++ b/src/data/things/homepage-layout.js @@ -1,3 +1,5 @@ +export const HOMEPAGE_LAYOUT_DATA_FILE = 'homepage.yaml'; + import {input} from '#composite'; import find from '#find'; import Thing from '#thing'; @@ -182,4 +184,40 @@ export class HomepageLayoutAlbumsRow extends HomepageLayoutRow { 'Actions': {property: 'actionLinks'}, }, }); + + static [Thing.getYamlLoadingSpec] = ({ + documentModes: {headerAndEntries}, // Kludge, see below + thingConstructors: { + HomepageLayout, + HomepageLayoutAlbumsRow, + }, + }) => ({ + title: `Process homepage layout file`, + + // Kludge: This benefits from the same headerAndEntries style messaging as + // albums and tracks (for example), but that document mode is designed to + // support multiple files, and only one is actually getting processed here. + files: [HOMEPAGE_LAYOUT_DATA_FILE], + + documentMode: headerAndEntries, + headerDocumentThing: HomepageLayout, + entryDocumentThing: document => { + switch (document['Type']) { + case 'albums': + return HomepageLayoutAlbumsRow; + default: + throw new TypeError(`No processDocument function for row type ${document['Type']}!`); + } + }, + + save(results) { + if (!results[0]) { + return; + } + + const {header: homepageLayout, entries: rows} = results[0]; + Object.assign(homepageLayout, {rows}); + return {homepageLayout}; + }, + }); } -- cgit 1.3.0-6-gf8a5