From 27d366fd2de98d816ef0698a1a6d5b4d59b388ca Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 5 May 2022 19:36:59 -0300 Subject: support albums and tracks without release dates --- src/misc-templates.js | 20 +++++++---------- src/page/album.js | 9 ++++---- src/page/artist.js | 56 +++++++++++++++++++----------------------------- src/page/group.js | 26 +++++++++++----------- src/page/track.js | 5 ++--- src/strings-default.json | 3 ++- src/util/wiki-data.js | 19 +++++++++++++++- 7 files changed, 70 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/misc-templates.js b/src/misc-templates.js index 995aaa2b..6289a737 100644 --- a/src/misc-templates.js +++ b/src/misc-templates.js @@ -10,10 +10,6 @@ import { getColors } from './util/colors.js'; -import { - UNRELEASED_TRACKS_DIRECTORY -} from './util/magic-constants.js'; - import { unique } from './util/sugar.js'; @@ -75,19 +71,15 @@ export function generateChronologyLinks(currentThing, { } return contributions.map(({ who: artist }) => { - const things = sortByDate(unique(getThings(artist)), dateKey); - const releasedThings = things.filter(thing => { - const album = albumData.includes(thing) ? thing : thing.album; - return !(album && album.directory === UNRELEASED_TRACKS_DIRECTORY); - }); - const index = releasedThings.indexOf(currentThing); + const things = sortByDate(unique(getThings(artist)).filter(t => t[dateKey]), dateKey); + const index = things.indexOf(currentThing); if (index === -1) return ''; // TODO: This can pro8a8ly 8e made to use generatePreviousNextLinks? // We'd need to make generatePreviousNextLinks use toAnythingMan tho. - const previous = releasedThings[index - 1]; - const next = releasedThings[index + 1]; + const previous = things[index - 1]; + const next = things[index + 1]; const parts = [ previous && linkAnythingMan(previous, { color: false, @@ -99,6 +91,10 @@ export function generateChronologyLinks(currentThing, { }) ].filter(Boolean); + if (!parts.length) { + return ''; + } + const stringOpts = { index: strings.count.index(index + 1, {strings}), artist: link.artist(artist) diff --git a/src/page/album.js b/src/page/album.js index eac0a9f3..66d4bfae 100644 --- a/src/page/album.js +++ b/src/page/album.js @@ -168,7 +168,7 @@ export function write(album, {wikiData}) { showIcons: true }) }), - strings('releaseInfo.released', { + album.date && strings('releaseInfo.released', { date: strings.count.date(album.date) }), (album.coverArtDate && @@ -328,9 +328,10 @@ export function generateAlbumSidebar(album, currentTrack, { const { groups } = album; const groupParts = groups.map(group => { - const index = group.albums.indexOf(album); - const next = group.albums[index + 1]; - const previous = group.albums[index - 1]; + const albums = group.albums.filter(album => album.date); + const index = albums.indexOf(album); + const next = index >= 0 && albums[index + 1]; + const previous = index > 0 && albums[index - 1]; return {group, next, previous}; }).map(({group, next, previous}) => fixWS`

${ diff --git a/src/page/artist.js b/src/page/artist.js index 38ca76d6..146b75a5 100644 --- a/src/page/artist.js +++ b/src/page/artist.js @@ -8,10 +8,6 @@ import fixWS from 'fix-whitespace'; import * as html from '../util/html.js'; -import { - UNRELEASED_TRACKS_DIRECTORY -} from '../util/magic-constants.js'; - import { bindOpts, unique @@ -82,9 +78,6 @@ export function write(artist, {wikiData}) { ...artist.tracksAsContributor ?? [] ])); - const unreleasedTracks = allTracks.filter(track => track.album.directory === UNRELEASED_TRACKS_DIRECTORY); - const releasedTracks = allTracks.filter(track => track.album.directory !== UNRELEASED_TRACKS_DIRECTORY); - const chunkTracks = tracks => ( chunkByProperties(tracks.map(track => ({ track, @@ -107,10 +100,8 @@ export function write(artist, {wikiData}) { duration: getTotalDuration(chunk), }))); - const unreleasedTrackListChunks = chunkTracks(unreleasedTracks); - const releasedTrackListChunks = chunkTracks(releasedTracks); - - const totalReleasedDuration = getTotalDuration(releasedTracks); + const trackListChunks = chunkTracks(allTracks); + const totalDuration = getTotalDuration(allTracks); const countGroups = things => { const usedGroups = things.flatMap(thing => thing.groups || thing.album?.groups || []); @@ -123,7 +114,7 @@ export function write(artist, {wikiData}) { .sort((a, b) => b.contributions - a.contributions); }; - const musicGroups = countGroups(releasedTracks); + const musicGroups = countGroups(allTracks); const artGroups = countGroups(artThingsAll); let flashes, flashListChunks; @@ -176,11 +167,20 @@ export function write(artist, {wikiData}) { }) => fixWS`
${chunks.map(({date, album, chunk, duration}) => fixWS` -
${strings('artistPage.creditList.album.withDate.withDuration', { - album: link.album(album), - date: strings.count.date(date), - duration: strings.count.duration(duration, {approximate: true}) - })}
+
${ + (date && duration) ? strings('artistPage.creditList.album.withDate.withDuration', { + album: link.album(album), + date: strings.count.date(date), + duration: strings.count.duration(duration, {approximate: true}) + }) : date ? strings('artistPage.creditList.album.withDate', { + album: link.album(album), + date: strings.count.date(date) + }) : duration ? strings('artistPage.creditList.album.withDuration', { + album: link.album(album), + duration: strings.count.duration(duration, {approximate: true}) + }) : strings('artistPage.creditList.album', { + album: link.album(album) + })}
    ${(chunk .map(({track, ...props}) => ({ @@ -256,10 +256,7 @@ export function write(artist, {wikiData}) { tracks: { asArtist: artist.tracksAsArtist.map(serializeArtistsAndContrib('artistContribs')), asContributor: artist.tracksAsContributor.map(serializeArtistsAndContrib('contributorContribs')), - chunked: { - released: serializeTrackListChunks(releasedTrackListChunks), - unreleased: serializeTrackListChunks(unreleasedTrackListChunks) - } + chunked: serializeTrackListChunks(trackListChunks) } }; } @@ -312,22 +309,17 @@ export function write(artist, {wikiData}) { })}

    `}

    ${strings('misc.jumpTo.withLinks', { links: strings.list.unit([ - [ - [...releasedTracks, ...unreleasedTracks].length && `${strings('artistPage.trackList.title')}`, - unreleasedTracks.length && `(${strings('artistPage.unreleasedTrackList.title')})` - ].filter(Boolean).join(' '), + allTracks.length && `${strings('artistPage.trackList.title')}`, artThingsAll.length && `${strings('artistPage.artList.title')}`, wikiInfo.enableFlashesAndGames && flashes.length && `${strings('artistPage.flashList.title')}`, commentaryThings.length && `${strings('artistPage.commentaryList.title')}` ].filter(Boolean)) })}

    - ${(releasedTracks.length || unreleasedTracks.length) && fixWS` + ${allTracks.length && fixWS`

    ${strings('artistPage.trackList.title')}

    - `} - ${releasedTracks.length && fixWS`

    ${strings('artistPage.contributedDurationLine', { artist: artist.name, - duration: strings.count.duration(totalReleasedDuration, {approximate: true, unit: true}) + duration: strings.count.duration(totalDuration, {approximate: true, unit: true}) })}

    ${strings('artistPage.musicGroupsLine', { groups: strings.list.unit(musicGroups @@ -336,11 +328,7 @@ export function write(artist, {wikiData}) { contributions: strings.count.contributions(contributions) }))) })}

    - ${generateTrackList(releasedTrackListChunks)} - `} - ${unreleasedTracks.length && fixWS` -

    ${strings('artistPage.unreleasedTrackList.title')}

    - ${generateTrackList(unreleasedTrackListChunks)} + ${generateTrackList(trackListChunks)} `} ${artThingsAll.length && fixWS`

    ${strings('artistPage.artList.title')}

    diff --git a/src/page/group.js b/src/page/group.js index c51f0e38..0a6cee1e 100644 --- a/src/page/group.js +++ b/src/page/group.js @@ -4,10 +4,6 @@ import fixWS from 'fix-whitespace'; -import { - UNRELEASED_TRACKS_DIRECTORY -} from '../util/magic-constants.js'; - import * as html from '../util/html.js'; import { @@ -24,9 +20,9 @@ export function targets({wikiData}) { export function write(group, {wikiData}) { const { listingSpec, wikiInfo } = wikiData; - const releasedAlbums = group.albums.filter(album => album.directory !== UNRELEASED_TRACKS_DIRECTORY); - const releasedTracks = releasedAlbums.flatMap(album => album.tracks); - const totalDuration = getTotalDuration(releasedTracks); + const { albums } = group; + const tracks = albums.flatMap(album => album.tracks); + const totalDuration = getTotalDuration(tracks); const albumLines = group.albums.map(album => ({ album, @@ -70,10 +66,14 @@ export function write(group, {wikiData}) { }

      ${albumLines.map(({ album, otherGroup }) => { - const item = strings('groupInfoPage.albumList.item', { - year: album.date.getFullYear(), - album: link.album(album) - }); + const item = (album.date + ? strings('groupInfoPage.albumList.item', { + year: album.date.getFullYear(), + album: link.album(album) + }) + : strings('groupInfoPage.albumList.item.withoutYear', { + album: link.album(album) + })); return html.tag('li', (otherGroup ? strings('groupInfoPage.albumList.item.withAccent', { item, @@ -127,8 +127,8 @@ export function write(group, {wikiData}) {

      ${strings('groupGalleryPage.title', {group: group.name})}

      ${ strings('groupGalleryPage.infoLine', { - tracks: `${strings.count.tracks(releasedTracks.length, {unit: true})}`, - albums: `${strings.count.albums(releasedAlbums.length, {unit: true})}`, + tracks: `${strings.count.tracks(tracks.length, {unit: true})}`, + albums: `${strings.count.albums(albums.length, {unit: true})}`, time: `${strings.count.duration(totalDuration, {unit: true})}` }) }

      diff --git a/src/page/track.js b/src/page/track.js index 960f00ce..c27b2b65 100644 --- a/src/page/track.js +++ b/src/page/track.js @@ -13,8 +13,7 @@ import { import * as html from '../util/html.js'; import { - OFFICIAL_GROUP_DIRECTORY, - UNRELEASED_TRACKS_DIRECTORY + OFFICIAL_GROUP_DIRECTORY } from '../util/magic-constants.js'; import { @@ -181,7 +180,7 @@ export function write(track, {wikiData}) { showIcons: true }) }), - album.directory !== UNRELEASED_TRACKS_DIRECTORY && strings('releaseInfo.released', { + track.date && strings('releaseInfo.released', { date: strings.count.date(track.date) }), (track.coverArtDate && diff --git a/src/strings-default.json b/src/strings-default.json index 1fc6d8a4..1c5fbc68 100644 --- a/src/strings-default.json +++ b/src/strings-default.json @@ -172,6 +172,7 @@ "artistPage.title": "{ARTIST}", "artistPage.creditList.album": "{ALBUM}", "artistPage.creditList.album.withDate": "{ALBUM} ({DATE})", + "artistPage.creditList.album.withDuration": "{ALBUM} ({DURATION})", "artistPage.creditList.album.withDate.withDuration": "{ALBUM} ({DATE}; {DURATION})", "artistPage.creditList.flashAct": "{ACT}", "artistPage.creditList.flashAct.withDateRange": "{ACT} ({DATE_RANGE})", @@ -191,7 +192,6 @@ "artistPage.artGroupsLine": "Contributed art to groups: {GROUPS}", "artistPage.groupsLine.item": "{GROUP} ({CONTRIBUTIONS})", "artistPage.trackList.title": "Tracks", - "artistPage.unreleasedTrackList.title": "Unreleased Tracks", "artistPage.artList.title": "Art", "artistPage.flashList.title": "Flashes & Games", "artistPage.commentaryList.title": "Commentary", @@ -217,6 +217,7 @@ "groupInfoPage.viewAlbumGallery.link": "album gallery", "groupInfoPage.albumList.title": "Albums", "groupInfoPage.albumList.item": "({YEAR}) {ALBUM}", + "groupInfoPage.albumList.item.withoutYear": "{ALBUM}", "groupInfoPage.albumList.item.withAccent": "{ITEM} {ACCENT}", "groupInfoPage.albumList.item.otherGroupAccent": "(from {GROUP})", "groupGalleryPage.title": "{GROUP} - Gallery", diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 6891a4c6..6d0db2c7 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -83,7 +83,24 @@ export function sortByDate(data, dateKey = 'date') { // Just to 8e clear: sort is a mutating function! I only return the array // 8ecause then you don't have to define it as a separate varia8le 8efore // passing it into this function. - return data.sort((a, b) => a[dateKey] - b[dateKey]); + return data.sort(({ [dateKey]: a }, { [dateKey]: b }) => { + // It's possible for objects with and without dates to be mixed + // together in the same array. If that's the case, we put all items + // without dates at the end. + if (a && b) { + return a - b; + } else if (a) { + return -1; + } else if (b) { + return 1; + } else { + // If neither of the items being compared have a date, don't move + // them relative to each other. This is basically the same as + // filtering out all non-date items and then pushing them at the + // end after sorting the rest. + return 0; + } + }); } // Same details as the sortByDate, 8ut for covers~ -- cgit 1.3.0-6-gf8a5