« get me outta code hell

content, data: generateWikiHomepageActionsRow - 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>2025-02-11 10:56:46 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-02-12 07:43:59 -0400
commit19d9c3a3d16ed08b2d0c9e09259ffb79a27cd3e9 (patch)
tree28f4576eae41596e8436525fe86bc9609fe2be09 /src
parent7ee12e72ae59f06dcde10f330dbfd023ae04709d (diff)
content, data: generateWikiHomepageActionsRow
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateCoverCarousel.js13
-rw-r--r--src/content/dependencies/generateWikiHomepageActionsRow.js22
-rw-r--r--src/content/dependencies/generateWikiHomepageAlbumsRow.js12
-rw-r--r--src/content/dependencies/generateWikiHomepageSection.js5
-rw-r--r--src/data/things/homepage-layout.js31
5 files changed, 57 insertions, 26 deletions
diff --git a/src/content/dependencies/generateCoverCarousel.js b/src/content/dependencies/generateCoverCarousel.js
index 69220da6..430f651e 100644
--- a/src/content/dependencies/generateCoverCarousel.js
+++ b/src/content/dependencies/generateCoverCarousel.js
@@ -2,24 +2,16 @@ import {empty, repeat, stitchArrays} from '#sugar';
 import {getCarouselLayoutForNumberOfItems} from '#wiki-data';
 
 export default {
-  contentDependencies: ['generateGridActionLinks'],
   extraDependencies: ['html'],
 
-  relations(relation) {
-    return {
-      actionLinks: relation('generateGridActionLinks'),
-    };
-  },
-
   slots: {
     images: {validate: v => v.strictArrayOf(v.isHTML)},
     links: {validate: v => v.strictArrayOf(v.isHTML)},
 
     lazy: {validate: v => v.anyOf(v.isWholeNumber, v.isBoolean)},
-    actionLinks: {validate: v => v.sparseArrayOf(v.isHTML)},
   },
 
-  generate(relations, slots, {html}) {
+  generate(slots, {html}) {
     const stitched =
       stitchArrays({
         image: slots.images,
@@ -58,9 +50,6 @@ export default {
                     }),
                 })))),
         ])),
-
-      relations.actionLinks
-        .slot('actionLinks', slots.actionLinks),
     ]);
   },
 };
diff --git a/src/content/dependencies/generateWikiHomepageActionsRow.js b/src/content/dependencies/generateWikiHomepageActionsRow.js
new file mode 100644
index 00000000..9f501099
--- /dev/null
+++ b/src/content/dependencies/generateWikiHomepageActionsRow.js
@@ -0,0 +1,22 @@
+export default {
+  contentDependencies: ['generateGridActionLinks', 'transformContent'],
+
+  relations: (relation, row) => ({
+    template:
+      relation('generateGridActionLinks'),
+
+    links:
+      row.actionLinks
+        .map(content => relation('transformContent', content)),
+  }),
+
+  generate: (relations) =>
+    relations.template.slots({
+      actionLinks:
+        relations.links
+          .map(contents =>
+            contents
+              .slot('mode', 'single-link')
+              .content),
+    }),
+};
diff --git a/src/content/dependencies/generateWikiHomepageAlbumsRow.js b/src/content/dependencies/generateWikiHomepageAlbumsRow.js
index b8e56a97..258e5fe1 100644
--- a/src/content/dependencies/generateWikiHomepageAlbumsRow.js
+++ b/src/content/dependencies/generateWikiHomepageAlbumsRow.js
@@ -7,7 +7,6 @@ export default {
     'generateCoverGrid',
     'image',
     'linkAlbum',
-    'transformContent',
   ],
 
   extraDependencies: ['language', 'wikiData'],
@@ -60,10 +59,6 @@ export default {
     images:
       sprawl.albums
         .map(album => relation('image', album.artTags)),
-
-    actionLinks:
-      row.actionLinks
-        .map(content => relation('transformContent', content)),
   }),
 
   data: (sprawl, row) => ({
@@ -106,13 +101,6 @@ export default {
               }),
             }));
 
-    commonSlots.actionLinks =
-      relations.actionLinks
-        .map(contents =>
-          contents
-            .slot('mode', 'single-link')
-            .content);
-
     switch (data.displayStyle) {
       case 'grid':
         return relations.coverGrid.slots({
diff --git a/src/content/dependencies/generateWikiHomepageSection.js b/src/content/dependencies/generateWikiHomepageSection.js
index 15299dd4..963c5dde 100644
--- a/src/content/dependencies/generateWikiHomepageSection.js
+++ b/src/content/dependencies/generateWikiHomepageSection.js
@@ -1,6 +1,7 @@
 export default {
   contentDependencies: [
     'generateColorStyleAttribute',
+    'generateWikiHomepageActionsRow',
     'generateWikiHomepageAlbumsRow',
   ],
 
@@ -12,7 +13,9 @@ export default {
 
     rows:
       homepageSection.rows.map(row =>
-        (row.type === 'albums'
+        (row.type === 'actions'
+          ? relation('generateWikiHomepageActionsRow', row)
+       : row.type === 'albums'
           ? relation('generateWikiHomepageAlbumsRow', row)
           : null)),
   }),
diff --git a/src/data/things/homepage-layout.js b/src/data/things/homepage-layout.js
index 3287d6f0..fa352ae7 100644
--- a/src/data/things/homepage-layout.js
+++ b/src/data/things/homepage-layout.js
@@ -80,6 +80,8 @@ export class HomepageLayout extends Thing {
 
       if (document['Row']) {
         switch (document['Row']) {
+          case 'actions':
+            return HomepageLayoutActionsRow;
           case 'albums':
             return HomepageLayoutAlbumsRow;
           default:
@@ -210,6 +212,34 @@ export class HomepageLayoutRow extends Thing {
   }
 }
 
+export class HomepageLayoutActionsRow extends HomepageLayoutRow {
+  static [Thing.friendlyName] = `Homepage Actions Row`;
+
+  static [Thing.getPropertyDescriptors] = (opts) => ({
+    ...HomepageLayoutRow[Thing.getPropertyDescriptors](opts),
+
+    // Update & expose
+
+    actionLinks: {
+      flags: {update: true, expose: true},
+      update: {validate: validateArrayItems(isString)},
+    },
+
+    // Expose only
+
+    type: {
+      flags: {expose: true},
+      expose: {compute: () => 'actions'},
+    },
+  });
+
+  static [Thing.yamlDocumentSpec] = Thing.extendDocumentSpec(HomepageLayoutRow, {
+    fields: {
+      'Actions': {property: 'actionLinks'},
+    },
+  });
+}
+
 export class HomepageLayoutAlbumsRow extends HomepageLayoutRow {
   static [Thing.friendlyName] = `Homepage Albums Row`;
 
@@ -282,7 +312,6 @@ export class HomepageLayoutAlbumsRow extends HomepageLayoutRow {
       'Group': {property: 'sourceGroup'},
       'Count': {property: 'countAlbumsFromGroup'},
       'Albums': {property: 'sourceAlbums'},
-      'Actions': {property: 'actionLinks'},
     },
   });
 }