« get me outta code hell

content: listAlbumsByDateAdded + chunk listings - 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-07-02 16:03:46 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-02 16:03:46 -0300
commit35e86b12f1108a4c365a2698835adc6a4b55b377 (patch)
treebaa41e6a0fb8084866c65f454071795800fd4f82
parent83325d6034a1f7ee1d861b8179c0edb9a7e0537d (diff)
content: listAlbumsByDateAdded + chunk listings
-rw-r--r--src/content/dependencies/generateListingPage.js36
-rw-r--r--src/content/dependencies/listAlbumsByDateAdded.js59
-rw-r--r--src/listing-spec.js28
-rw-r--r--src/strings-default.json4
4 files changed, 92 insertions, 35 deletions
diff --git a/src/content/dependencies/generateListingPage.js b/src/content/dependencies/generateListingPage.js
index 27c81284..93b35497 100644
--- a/src/content/dependencies/generateListingPage.js
+++ b/src/content/dependencies/generateListingPage.js
@@ -2,6 +2,7 @@ import {empty, stitchArrays} from '../../util/sugar.js';
 
 export default {
   contentDependencies: [
+    'generateContentHeading',
     'generateListingSidebar',
     'generatePageLayout',
     'linkListing',
@@ -22,6 +23,9 @@ export default {
     relations.listingsIndexLink =
       relation('linkListingIndex');
 
+    relations.chunkHeading =
+      relation('generateContentHeading');
+
     if (listing.target.listings.length > 1) {
       relations.sameTargetListingLinks =
         listing.target.listings
@@ -54,13 +58,12 @@ export default {
   },
 
   slots: {
-    type: {
-      validate: v => v.is('rows'),
-    },
+    type: {validate: v => v.is('rows', 'chunks'),},
+
+    rows: {validate: v => v.arrayOf(v.isObject)},
 
-    rows: {
-      validate: v => v.arrayOf(v.isObject),
-    },
+    chunkTitles: {validate: v => v.arrayOf(v.isObject)},
+    chunkRows: {validate: v => v.arrayOf(v.isObject)},
   },
 
   generate(data, relations, slots, {html, language}) {
@@ -98,6 +101,27 @@ export default {
             slots.rows.map(row =>
               html.tag('li',
                 language.$(`listingPage.${data.stringsKey}.item`, row)))),
+
+        slots.type === 'chunks' &&
+          html.tag('dl',
+            stitchArrays({
+              title: slots.chunkTitles,
+              rows: slots.chunkRows,
+            }).map(({title, rows}) => [
+                relations.chunkHeading
+                  .clone()
+                  .slots({
+                    tag: 'dt',
+                    title:
+                      language.$(`listingPage.${data.stringsKey}.chunk.title`, title),
+                  }),
+
+                html.tag('dd',
+                  html.tag('ul',
+                    rows.map(row =>
+                      html.tag('li',
+                        language.$(`listingPage.${data.stringsKey}.chunk.item`, row))))),
+              ])),
       ],
 
       navLinkStyle: 'hierarchical',
diff --git a/src/content/dependencies/listAlbumsByDateAdded.js b/src/content/dependencies/listAlbumsByDateAdded.js
new file mode 100644
index 00000000..e2ff8461
--- /dev/null
+++ b/src/content/dependencies/listAlbumsByDateAdded.js
@@ -0,0 +1,59 @@
+import {chunkByProperties, sortAlphabetically} from '../../util/wiki-data.js';
+
+export default {
+  contentDependencies: ['generateListingPage', 'linkAlbum'],
+  extraDependencies: ['language', 'wikiData'],
+
+  sprawl({albumData}) {
+    return {albumData};
+  },
+
+  query({albumData}, spec) {
+    return {
+      spec,
+
+      chunks:
+        chunkByProperties(
+          sortAlphabetically(albumData.filter(a => a.dateAddedToWiki))
+            .sort((a, b) => {
+              if (a.dateAddedToWiki < b.dateAddedToWiki) return -1;
+              if (a.dateAddedToWiki > b.dateAddedToWiki) return 1;
+            }),
+          ['dateAddedToWiki']),
+    };
+  },
+
+  relations(relation, query) {
+    return {
+      page: relation('generateListingPage', query.spec),
+
+      albumLinks:
+        query.chunks.map(({chunk}) =>
+          chunk.map(album => relation('linkAlbum', album))),
+    };
+  },
+
+  data(query) {
+    return {
+      dates:
+        query.chunks.map(({dateAddedToWiki}) => dateAddedToWiki),
+    };
+  },
+
+  generate(data, relations, {language}) {
+    return relations.page.slots({
+      type: 'chunks',
+
+      chunkTitles:
+        data.dates.map(date => ({
+          date: language.formatDate(date),
+        })),
+
+      chunkRows:
+        relations.albumLinks.map(albumLinks =>
+          albumLinks.map(link => ({
+            album: link,
+          }))),
+    });
+  },
+};
diff --git a/src/listing-spec.js b/src/listing-spec.js
index e9be40cd..844d241d 100644
--- a/src/listing-spec.js
+++ b/src/listing-spec.js
@@ -53,33 +53,7 @@ listingSpec.push({
 listingSpec.push({
   directory: 'albums/by-date-added',
   stringsKey: 'listAlbums.byDateAdded',
-
-  data: ({wikiData: {albumData}}) =>
-    chunkByProperties(
-      sortAlphabetically(albumData.filter(a => a.dateAddedToWiki))
-        .sort((a, b) => {
-          if (a.dateAddedToWiki < b.dateAddedToWiki) return -1;
-          if (a.dateAddedToWiki > b.dateAddedToWiki) return 1;
-        }),
-      ['dateAddedToWiki']),
-
-  html: (data, {html, language, link}) =>
-    html.tag('dl',
-      data.flatMap(({dateAddedToWiki, chunk: albums}) => [
-        html.tag('dt',
-          {class: ['content-heading']},
-          language.$('listingPage.listAlbums.byDateAdded.date', {
-            date: language.formatDate(dateAddedToWiki),
-          })),
-
-        html.tag('dd',
-          html.tag('ul',
-            albums.map((album) =>
-              html.tag('li',
-                language.$('listingPage.listAlbums.byDateAdded.album', {
-                  album: link.album(album),
-                }))))),
-      ])),
+  contentFunction: 'listAlbumsByDateAdded',
 });
 
 listingSpec.push({
diff --git a/src/strings-default.json b/src/strings-default.json
index 4771dc4a..4db11053 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -352,8 +352,8 @@
   "listingPage.listAlbums.byDate.item": "{ALBUM} ({DATE})",
   "listingPage.listAlbums.byDateAdded.title.short": "...by Date Added to Wiki",
   "listingPage.listAlbums.byDateAdded.title": "Albums - by Date Added to Wiki",
-  "listingPage.listAlbums.byDateAdded.date": "{DATE}",
-  "listingPage.listAlbums.byDateAdded.album": "{ALBUM}",
+  "listingPage.listAlbums.byDateAdded.chunk.title": "{DATE}",
+  "listingPage.listAlbums.byDateAdded.chunk.item": "{ALBUM}",
   "listingPage.listArtists.byName.title": "Artists - by Name",
   "listingPage.listArtists.byName.title.short": "...by Name",
   "listingPage.listArtists.byName.item": "{ARTIST} ({CONTRIBUTIONS})",