diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-06-10 17:07:01 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-06-10 17:07:01 -0300 |
commit | 531219642b93a5dc236f217d22f024fb2707191f (patch) | |
tree | 644449168c11152546f883bf4122a97fd17d0d16 /src/listing-spec.js | |
parent | 6e430bcdf251fbc8cbcfd4c48a8bbc1bf134120f (diff) |
various sorting improvements across the board
- several bugs introduced during data restructure fixed - a few areas where sorting functions were present but completely ineffective (albeit harmlessly so) fixed - new composite sorting utils are more deterministic by considering multiple factors instead of e.g. only name, only date - component sorting functions can be combined and pay more attention to determinism and only moving items when it's covered by the scope of the component (i.e. they can more readily be composited / used together) - names are normalized in a more particular manner (for alphabetical sorting) - accents are stripped, "ü" sorts as "u" - punctuation is stripped, "dave's" sorts as "daves" - (some) diacritics are expanded, "ff" sorts as "ff" - any sequential whitespace treated as one typical space - whitespace is trimmed from start and end - english prefix "a" / "an" stripped in addition to "the" - alphabetical sorting uses localeCompare and considers numeric strings more naturally, "Homestuck Vol. 10" sorts after "Homestuck Vol. 5"
Diffstat (limited to 'src/listing-spec.js')
-rw-r--r-- | src/listing-spec.js | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/listing-spec.js b/src/listing-spec.js index bb0c0a5b..1c1dbd5e 100644 --- a/src/listing-spec.js +++ b/src/listing-spec.js @@ -4,8 +4,8 @@ import { chunkByProperties, getArtistNumContributions, getTotalDuration, - sortByDate, - sortByName + sortAlphabetically, + sortChronologically, } from './util/wiki-data.js'; const listingSpec = [ @@ -14,8 +14,7 @@ const listingSpec = [ stringsKey: 'listAlbums.byName', data({wikiData}) { - return wikiData.albumData.slice() - .sort(sortByName); + return sortAlphabetically(wikiData.albumData.slice()); }, row(album, {link, language}) { @@ -66,7 +65,7 @@ const listingSpec = [ stringsKey: 'listAlbums.byDate', data({wikiData}) { - return sortByDate(wikiData.albumData.filter(album => album.date)); + return sortChronologically(wikiData.albumData.filter(album => album.date)); }, row(album, {link, language}) { @@ -114,8 +113,7 @@ const listingSpec = [ stringsKey: 'listArtists.byName', data({wikiData}) { - return wikiData.artistData.slice() - .sort(sortByName) + return sortAlphabetically(wikiData.artistData.slice()) .map(artist => ({artist, contributions: getArtistNumContributions(artist)})); }, @@ -254,22 +252,23 @@ const listingSpec = [ stringsKey: 'listArtists.byLatest', data({wikiData}) { - const reversedTracks = wikiData.trackData.filter(t => t.date).reverse(); - const reversedArtThings = wikiData.justEverythingSortedByArtDateMan.filter(t => t.date).reverse(); + const reversedTracks = sortChronologically(wikiData.trackData.filter(t => t.date)).reverse(); + const reversedArtThings = sortChronologically([...wikiData.trackData, ...wikiData.albumData].filter(t => t.coverArtDate)).reverse(); return { - toTracks: sortByDate(wikiData.artistData + toTracks: sortChronologically(wikiData.artistData .map(artist => ({ artist, + directory: artist.directory, + name: artist.name, date: reversedTracks.find(track => ([ ...track.artistContribs ?? [], ...track.contributorContribs ?? [] ].some(({ who }) => who === artist)))?.date })) - .filter(({ date }) => date) - .sort((a, b) => a.name < b.name ? 1 : a.name > b.name ? -1 : 0)).reverse(), + .filter(({ date }) => date)).reverse(), - toArtAndFlashes: sortByDate(wikiData.artistData + toArtAndFlashes: sortChronologically(wikiData.artistData .map(artist => { const thing = reversedArtThings.find(thing => ([ ...thing.coverArtistContribs ?? [], @@ -277,6 +276,8 @@ const listingSpec = [ ].some(({ who }) => who === artist))); return thing && { artist, + directory: artist.directory, + name: artist.name, date: (thing.coverArtistContribs?.some(({ who }) => who === artist) ? thing.coverArtDate : thing.date) @@ -332,7 +333,7 @@ const listingSpec = [ directory: 'groups/by-name', stringsKey: 'listGroups.byName', condition: ({wikiData}) => wikiData.wikiInfo.enableGroupUI, - data: ({wikiData}) => wikiData.groupData.slice().sort(sortByName), + data: ({wikiData}) => sortAlphabetically(wikiData.groupData.slice()), row(group, {link, language}) { return language.$('listingPage.listGroups.byCategory.group', { @@ -437,11 +438,13 @@ const listingSpec = [ condition: ({wikiData}) => wikiData.wikiInfo.enableGroupUI, data({wikiData}) { - return sortByDate(wikiData.groupData + return sortChronologically(wikiData.groupData .map(group => { const albums = group.albums.filter(a => a.date); return albums.length && { group, + directory: group.directory, + name: group.name, date: albums[albums.length - 1].date }; }) @@ -456,8 +459,8 @@ const listingSpec = [ // l8ter, that flips them, and UMSPAF ends up displaying 8efore // Fandom. So we do an extra reverse here, which will fix that // and only affect groups that share the same d8te (8ecause - // groups that don't will 8e moved 8y the sortByDate call - // surrounding this). + // groups that don't will 8e moved 8y the sortChronologically + // call surrounding this). .reverse()).reverse() }, @@ -474,7 +477,7 @@ const listingSpec = [ stringsKey: 'listTracks.byName', data({wikiData}) { - return wikiData.trackData.slice().sort(sortByName); + return sortAlphabetically(wikiData.trackData.slice()); }, row(track, {link, language}) { @@ -516,7 +519,7 @@ const listingSpec = [ data({wikiData}) { return chunkByProperties( - sortByDate(wikiData.trackData.filter(t => t.date)), + sortChronologically(wikiData.trackData.filter(t => t.date)), ['album', 'date'] ); }, @@ -659,7 +662,7 @@ const listingSpec = [ html(flashData, {link, language}) { return fixWS` <dl> - ${sortByDate(flashData.slice()).map(flash => fixWS` + ${sortChronologically(flashData.slice()).map(flash => fixWS` <dt>${language.$('listingPage.listTracks.inFlashes.byFlash.flash', { flash: link.flash(flash), date: language.formatDate(flash.date) @@ -715,9 +718,7 @@ const listingSpec = [ condition: ({wikiData}) => wikiData.wikiInfo.enableArtTagUI, data({wikiData}) { - return wikiData.artTagData - .filter(tag => !tag.isContentWarning) - .sort(sortByName) + return sortAlphabetically(wikiData.artTagData.filter(tag => !tag.isContentWarning)) .map(tag => ({tag, timesUsed: tag.taggedInThings?.length})); }, |