diff options
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 |
commit | eb8b316bb9af7d34720de1fa8f8dbd4b81513b32 (patch) | |
tree | 22d435e702b89344304928b7a860a5326357f192 /src/data/things/homepage-layout.js | |
parent | b30585187480a270826767eaf97e1acc66126072 (diff) |
data, yaml: store data step info on Thing constructors
Diffstat (limited to 'src/data/things/homepage-layout.js')
-rw-r--r-- | src/data/things/homepage-layout.js | 38 |
1 files changed, 38 insertions, 0 deletions
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}; + }, + }); } |