diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-04-10 19:57:12 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-06-18 22:56:05 -0300 |
commit | cf7e1def135f925fefcde55e130c76598ab69cd4 (patch) | |
tree | b316a9141d3d5447fd90f682778404288e826c9d | |
parent | 019e351a9560b09256dfaf99fea9252029df1701 (diff) |
content: gAIPChunk: consolidate date processing
4 files changed, 46 insertions, 54 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js index 3cda7d90..91edbe03 100644 --- a/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js +++ b/src/content/dependencies/generateArtistInfoPageArtworksChunkedList.js @@ -203,7 +203,7 @@ export default { chunk.slots({ mode: 'album', albumLink, - date, + dates: [date], items: stitchArrays({ diff --git a/src/content/dependencies/generateArtistInfoPageChunk.js b/src/content/dependencies/generateArtistInfoPageChunk.js index 40943914..c16d50f3 100644 --- a/src/content/dependencies/generateArtistInfoPageChunk.js +++ b/src/content/dependencies/generateArtistInfoPageChunk.js @@ -1,3 +1,5 @@ +import {empty} from '#sugar'; + export default { extraDependencies: ['html', 'language'], @@ -21,15 +23,33 @@ export default { mutable: false, }, - date: {validate: v => v.isDate}, - dateRangeStart: {validate: v => v.isDate}, - dateRangeEnd: {validate: v => v.isDate}, + dates: { + validate: v => v.sparseArrayOf(v.isDate), + }, duration: {validate: v => v.isDuration}, durationApproximate: {type: 'boolean'}, }, generate(slots, {html, language}) { + let earliestDate = null; + let latestDate = null; + let onlyDate = null; + + if (!empty(slots.dates)) { + earliestDate = + slots.dates + .reduce((a, b) => a <= b ? a : b); + + latestDate = + slots.dates + .reduce((a, b) => a <= b ? b : a); + + if (+earliestDate === +latestDate) { + onlyDate = earliestDate; + } + } + let accentedLink; accent: { @@ -40,9 +60,9 @@ export default { const options = {album: accentedLink}; const parts = ['artistPage.creditList.album']; - if (slots.date) { + if (onlyDate) { parts.push('withDate'); - options.date = language.formatDate(slots.date); + options.date = language.formatDate(onlyDate); } if (slots.duration) { @@ -63,16 +83,13 @@ export default { const options = {act: accentedLink}; const parts = ['artistPage.creditList.flashAct']; - if ( - slots.dateRangeStart && - slots.dateRangeEnd && - slots.dateRangeStart !== slots.dateRangeEnd - ) { - parts.push('withDateRange'); - options.dateRange = language.formatDateRange(slots.dateRangeStart, slots.dateRangeEnd); - } else if (slots.dateRangeStart || slots.date) { + if (onlyDate) { parts.push('withDate'); - options.date = language.formatDate(slots.dateRangeStart ?? slots.date); + options.date = language.formatDate(onlyDate); + } else if (earliestDate && latestDate) { + parts.push('withDateRange'); + options.dateRange = + language.formatDateRange(earliestDate, latestDate); } accentedLink = language.formatString(...parts, options); diff --git a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js index 447e697e..4338c7e6 100644 --- a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js +++ b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js @@ -82,11 +82,9 @@ export default { actNames: query.chunks.map(({act}) => act.name), - firstDates: - query.chunks.map(({chunk}) => chunk[0].flash.date ?? null), - - lastDates: - query.chunks.map(({chunk}) => chunk.at(-1).flash.date ?? null), + dates: + query.chunks.map(({chunk}) => + chunk.map(({flash}) => flash.date)), itemContributions: query.chunks.map(({chunk}) => @@ -103,8 +101,7 @@ export default { chunk: relations.chunks, actLink: relations.actLinks, actName: data.actNames, - firstDate: data.firstDates, - lastDate: data.lastDates, + dates: data.dates, items: relations.items, itemFlashLinks: relations.itemFlashLinks, @@ -113,8 +110,7 @@ export default { chunk, actLink, actName, - firstDate, - lastDate, + dates, items, itemFlashLinks, @@ -123,8 +119,7 @@ export default { chunk.slots({ mode: 'flash', flashActLink: actLink.slot('content', actName), - dateRangeStart: firstDate, - dateRangeEnd: lastDate, + dates, items: stitchArrays({ diff --git a/src/content/dependencies/generateArtistInfoPageTracksChunk.js b/src/content/dependencies/generateArtistInfoPageTracksChunk.js index cc9b898f..b42e4165 100644 --- a/src/content/dependencies/generateArtistInfoPageTracksChunk.js +++ b/src/content/dependencies/generateArtistInfoPageTracksChunk.js @@ -1,4 +1,4 @@ -import {empty, unique} from '#sugar'; +import {unique} from '#sugar'; import {getTotalDuration} from '#wiki-data'; export default { @@ -27,34 +27,17 @@ export default { data(_artist, album, trackContribLists) { const data = {}; - const allDates = - trackContribLists - .flat() - .filter(contrib => contrib.date) - .map(contrib => contrib.date); - - if (!empty(allDates)) { - const earliestDate = - allDates - .reduce((a, b) => a <= b ? a : b); - - const latestDate = - allDates - .reduce((a, b) => a <= b ? b : a); + const contribs = + trackContribLists.flat(); - if (+earliestDate === +latestDate) { - data.date = earliestDate; - } else { - data.earliestDate = earliestDate; - data.latestDate = latestDate; - } - } + data.dates = + contribs + .map(contrib => contrib.date); // TODO: Duration stuff should *maybe* be in proper data logic? Maaaybe? const durationTerms = unique( - trackContribLists - .flat() + contribs .filter(contrib => contrib.countInDurationTotals) .map(contrib => contrib.thing) .filter(track => track.isOriginalRelease) @@ -75,10 +58,7 @@ export default { albumLink: relations.albumLink, - date: data.date ?? null, - dateRangeStart: data.earliestDate ?? null, - dateRangeEnd: data.latestDate ?? null, - + dates: data.dates, duration: data.duration, durationApproximate: data.durationApproximate, |