diff options
| author | (quasar) nebula <qznebula@protonmail.com> | 2026-01-26 15:14:38 -0400 |
|---|---|---|
| committer | (quasar) nebula <qznebula@protonmail.com> | 2026-01-26 15:14:38 -0400 |
| commit | a074fd54107c51c4fcbfedbbf6df6eca539d19d3 (patch) | |
| tree | 4fec08106aa3054c1954c5fa4ade0fb880c5eeb3 /src/data/things/homepage-layout/HomepageLayout.js | |
| parent | 796e4bc1452b918bbf50a2e802b308f6ac20f2c2 (diff) | |
data, yaml: split yaml loading specs into src/data/files
Diffstat (limited to 'src/data/things/homepage-layout/HomepageLayout.js')
| -rw-r--r-- | src/data/things/homepage-layout/HomepageLayout.js | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/src/data/things/homepage-layout/HomepageLayout.js b/src/data/things/homepage-layout/HomepageLayout.js index e144bf80..1c432b53 100644 --- a/src/data/things/homepage-layout/HomepageLayout.js +++ b/src/data/things/homepage-layout/HomepageLayout.js @@ -1,8 +1,5 @@ -const HOMEPAGE_LAYOUT_DATA_FILE = 'homepage.yaml'; - import {V} from '#composite'; import Thing from '#thing'; -import {empty} from '#sugar'; import {isStringNonEmpty, validateArrayItems} from '#validators'; import {exposeConstant} from '#composite/control-flow'; @@ -39,90 +36,4 @@ export class HomepageLayout extends Thing { 'Navbar Links': {property: 'navbarLinks'}, }, }; - - static [Thing.getYamlLoadingSpec] = ({ - documentModes: {allInOne}, - thingConstructors: { - HomepageLayout, - HomepageLayoutActionsRow, - HomepageLayoutAlbumCarouselRow, - HomepageLayoutAlbumGridRow, - HomepageLayoutRow, - HomepageLayoutSection, - }, - }) => ({ - title: `Process homepage layout file`, - file: HOMEPAGE_LAYOUT_DATA_FILE, - - documentMode: allInOne, - documentThing: document => { - if (document['Homepage']) { - return HomepageLayout; - } - - if (document['Section']) { - return HomepageLayoutSection; - } - - if (document['Row']) { - switch (document['Row']) { - case 'actions': - return HomepageLayoutActionsRow; - case 'album carousel': - return HomepageLayoutAlbumCarouselRow; - case 'album grid': - return HomepageLayoutAlbumGridRow; - default: - throw new TypeError(`Unrecognized row type ${document['Row']}`); - } - } - - return null; - }, - - connect(results) { - if (!empty(results) && !(results[0] instanceof HomepageLayout)) { - throw new Error(`Expected 'Homepage' document at top of homepage layout file`); - } - - const homepageLayout = results[0]; - const sections = []; - - let currentSection = null; - let currentSectionRows = []; - - const closeCurrentSection = () => { - if (currentSection) { - for (const row of currentSectionRows) { - row.section = currentSection; - } - - currentSection.rows = currentSectionRows; - sections.push(currentSection); - - currentSection = null; - currentSectionRows = []; - } - }; - - for (const entry of results.slice(1)) { - if (entry instanceof HomepageLayout) { - throw new Error(`Expected only one 'Homepage' document in total`); - } else if (entry instanceof HomepageLayoutSection) { - closeCurrentSection(); - currentSection = entry; - } else if (entry instanceof HomepageLayoutRow) { - if (currentSection) { - currentSectionRows.push(entry); - } else { - throw new Error(`Expected a 'Section' document to add following rows into`); - } - } - } - - closeCurrentSection(); - - homepageLayout.sections = sections; - }, - }); } |