« get me outta code hell

content: generateListingPage: add chunkRowAttributes slot - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-09 15:48:36 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-09 15:48:36 -0400
commit443c2e42ad2731e63f40c9575e2c27001ed55bae (patch)
treea1d6964eba172d7725ab1319eb26954561ffdca5
parent150c414044662134ddf785e7411560e3a6051a03 (diff)
content: generateListingPage: add chunkRowAttributes slot
This refactors out the hard-coded 'rerelease' behavior.
-rw-r--r--src/content/dependencies/generateListingPage.js24
-rw-r--r--src/content/dependencies/listTracksByDate.js9
2 files changed, 26 insertions, 7 deletions
diff --git a/src/content/dependencies/generateListingPage.js b/src/content/dependencies/generateListingPage.js
index 45b7dc1b..403f891f 100644
--- a/src/content/dependencies/generateListingPage.js
+++ b/src/content/dependencies/generateListingPage.js
@@ -68,6 +68,7 @@ export default {
 
     chunkTitles: {validate: v => v.strictArrayOf(v.isObject)},
     chunkRows: {validate: v => v.strictArrayOf(v.isObject)},
+    chunkRowAttributes: {validate: v => v.strictArrayOf(v.optional(v.isObject))},
 
     showSkipToSection: {type: 'boolean', default: false},
     chunkIDs: {validate: v => v.strictArrayOf(v.isString)},
@@ -165,9 +166,17 @@ export default {
 
             stitchArrays({
               title: slots.chunkTitles,
-              rows: slots.chunkRows,
               id: slots.chunkIDs,
-            }).map(({title, rows, id}) => [
+
+              rows: slots.chunkRows,
+              rowAttributes: slots.chunkRowAttributes,
+            }).map(({
+                title,
+                id,
+
+                rows,
+                rowAttributes,
+              }) => [
                 relations.chunkHeading
                   .clone()
                   .slots({
@@ -178,10 +187,13 @@ export default {
 
                 html.tag('dd',
                   html.tag(listTag,
-                    rows.map(row =>
-                      html.tag('li',
-                        {class: row.stringsKey === 'rerelease' && 'rerelease'},
-                        formatListingString('chunk.item', row))))),
+                    stitchArrays({
+                      row: rows,
+                      attributes: rowAttributes ?? rows.map(() => null),
+                    }).map(({row, attributes}) =>
+                        html.tag('li',
+                          attributes,
+                          formatListingString('chunk.item', row))))),
               ]),
           ]),
       ],
diff --git a/src/content/dependencies/listTracksByDate.js b/src/content/dependencies/listTracksByDate.js
index d6546e67..25beb739 100644
--- a/src/content/dependencies/listTracksByDate.js
+++ b/src/content/dependencies/listTracksByDate.js
@@ -71,8 +71,15 @@ export default {
               rerelease: rereleases,
             }).map(({trackLink, rerelease}) =>
                 (rerelease
-                  ? {track: trackLink, stringsKey: 'rerelease'}
+                  ? {stringsKey: 'rerelease', track: trackLink}
                   : {track: trackLink}))),
+
+      chunkRowAttributes:
+        data.rereleases.map(rereleases =>
+          rereleases.map(rerelease =>
+            (rerelease
+              ? {class: 'rerelease'}
+              : null))),
     });
   },
 };