From 35e86b12f1108a4c365a2698835adc6a4b55b377 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 2 Jul 2023 16:03:46 -0300 Subject: content: listAlbumsByDateAdded + chunk listings --- src/content/dependencies/generateListingPage.js | 36 +++++++++++--- src/content/dependencies/listAlbumsByDateAdded.js | 59 +++++++++++++++++++++++ 2 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 src/content/dependencies/listAlbumsByDateAdded.js (limited to 'src/content/dependencies') 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, + }))), + }); + }, +}; -- cgit 1.3.0-6-gf8a5