From 01bd5cec3a83e9ced7715954e76dd820aa7e91dd Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 26 Mar 2026 16:44:07 -0300 Subject: content, wiki-data: sameDayAs --- src/common-util/wiki-data.js | 27 +++++++++++++++ .../dependencies/generateMusicVideoDateLine.js | 39 +++++----------------- 2 files changed, 36 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js index 42ff677e..ae186065 100644 --- a/src/common-util/wiki-data.js +++ b/src/common-util/wiki-data.js @@ -616,3 +616,30 @@ export const albumHasSubstantialCommentaryPage = album => album.tracks .flatMap(track => track.commentary) .filter(entry => !entry.isWikiEditorCommentary)); + +export function sameDayAs(givenDate, thing) { + if (!givenDate) return null; + + const compare = (a, b) => + a && b && + a.toDateString() === b.toDateString(); + + if (thing.isAlbum || thing.isTrack) { + const album = thing.isTrack ? thing.album : thing; + const track = thing.isTrack ? thing : null; + + if (compare(givenDate, album.date)) { + if (album.style === 'single') { + return 'single'; + } else { + return 'album'; + } + } + + if (compare(givenDate, track?.date)) { + return 'track'; + } + } + + return null; +} diff --git a/src/content/dependencies/generateMusicVideoDateLine.js b/src/content/dependencies/generateMusicVideoDateLine.js index 98992584..7b8b57f7 100644 --- a/src/content/dependencies/generateMusicVideoDateLine.js +++ b/src/content/dependencies/generateMusicVideoDateLine.js @@ -1,27 +1,4 @@ -function sameDay(musicVideo, thing) { - if (!musicVideo.dateIsSpecified) return null; - - const compare = (a, b) => - a && b && - a.toDateString() === b.toDateString(); - - const album = thing.isTrack ? thing.album : thing; - const track = thing.isTrack ? thing : null; - - if (compare(musicVideo.date, album.date)) { - if (album.style === 'single') { - return 'single'; - } else { - return 'album'; - } - } - - if (compare(musicVideo.date, track?.date)) { - return 'track'; - } - - return null; -} +import {sameDayAs} from '#wiki-data'; export default { data: (musicVideo, thing) => ({ @@ -31,22 +8,24 @@ export default { dateIsSpecified: musicVideo.dateIsSpecified, - sameDay: - sameDay(musicVideo, thing), + sameDayAs: + (musicVideo.dateIsSpecified + ? sameDayAs(musicVideo.date, thing) + : null), }), generate: (data, {language}) => language.encapsulate('misc.musicVideo.date', capsule => [ - data.sameDay === 'album' && + data.sameDayAs === 'album' && language.$(capsule, 'sameDayAsAlbum'), - data.sameDay === 'single' && + data.sameDayAs === 'single' && language.$(capsule, 'sameDayAsSingle'), - data.sameDay === 'track' && + data.sameDayAs === 'track' && language.$(capsule, 'sameDayAsTrack'), - data.sameDay === null && + data.sameDayAs === null && data.dateIsSpecified && language.$(capsule, { date: -- cgit 1.3.0-6-gf8a5