« get me outta code hell

various sorting improvements across the board - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/page
diff options
context:
space:
mode:
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
commit531219642b93a5dc236f217d22f024fb2707191f (patch)
tree644449168c11152546f883bf4122a97fd17d0d16 /src/page
parent6e430bcdf251fbc8cbcfd4c48a8bbc1bf134120f (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/page')
-rw-r--r--src/page/artist.js25
-rw-r--r--src/page/group.js9
-rw-r--r--src/page/track.js13
3 files changed, 31 insertions, 16 deletions
diff --git a/src/page/artist.js b/src/page/artist.js
index c15e0342..17ff5b66 100644
--- a/src/page/artist.js
+++ b/src/page/artist.js
@@ -16,7 +16,10 @@ import {
 import {
     chunkByProperties,
     getTotalDuration,
-    sortByDate
+    sortAlbumsTracksChronologically,
+    sortByDate,
+    sortByDirectory,
+    sortChronologically,
 } from '../util/wiki-data.js';
 
 // Page exports
@@ -30,19 +33,19 @@ export function write(artist, {wikiData}) {
 
     const { name, urls, contextNotes } = artist;
 
-    const artThingsAll = sortByDate(unique([
+    const artThingsAll = sortAlbumsTracksChronologically(unique([
         ...artist.albumsAsCoverArtist ?? [],
         ...artist.albumsAsWallpaperArtist ?? [],
         ...artist.albumsAsBannerArtist ?? [],
         ...artist.tracksAsCoverArtist ?? []
-    ]));
+    ]), {getDate: o => o.coverArtDate});
 
-    const artThingsGallery = sortByDate([
+    const artThingsGallery = sortAlbumsTracksChronologically([
         ...artist.albumsAsCoverArtist ?? [],
         ...artist.tracksAsCoverArtist ?? []
-    ]);
+    ], {getDate: o => o.coverArtDate});
 
-    const commentaryThings = sortByDate([
+    const commentaryThings = sortAlbumsTracksChronologically([
         ...artist.albumsAsCommentator ?? [],
         ...artist.tracksAsCommentator ?? []
     ]);
@@ -56,24 +59,24 @@ export function write(artist, {wikiData}) {
         key
     });
 
-    const artListChunks = chunkByProperties(sortByDate(artThingsAll.flatMap(thing =>
+    const artListChunks = chunkByProperties(artThingsAll.flatMap(thing =>
         (['coverArtistContribs', 'wallpaperArtistContribs', 'bannerArtistContribs']
             .map(key => getArtistsAndContrib(thing, key))
             .filter(({ contrib }) => contrib)
             .map(props => ({
                 album: thing.album || thing,
                 track: thing.album ? thing : null,
-                date: +(thing.coverArtDate || thing.date),
+                date: thing.date,
                 ...props
             })))
-    )), ['date', 'album']);
+    ), ['date', 'album']);
 
     const commentaryListChunks = chunkByProperties(commentaryThings.map(thing => ({
         album: thing.album || thing,
         track: thing.album ? thing : null
     })), ['album']);
 
-    const allTracks = sortByDate(unique([
+    const allTracks = sortAlbumsTracksChronologically(unique([
         ...artist.tracksAsArtist ?? [],
         ...artist.tracksAsContributor ?? []
     ]));
@@ -119,7 +122,7 @@ export function write(artist, {wikiData}) {
 
     let flashes, flashListChunks;
     if (wikiInfo.enableFlashesAndGames) {
-        flashes = sortByDate(artist.flashesAsContributor?.slice() ?? []);
+        flashes = sortChronologically(artist.flashesAsContributor?.slice() ?? []);
         flashListChunks = (
             chunkByProperties(flashes.map(flash => ({
                 act: flash.act,
diff --git a/src/page/group.js b/src/page/group.js
index eb401dd0..4eb8fb3e 100644
--- a/src/page/group.js
+++ b/src/page/group.js
@@ -8,7 +8,7 @@ import * as html from '../util/html.js';
 
 import {
     getTotalDuration,
-    sortByDate
+    sortChronologically,
 } from '../util/wiki-data.js';
 
 // Page exports
@@ -142,7 +142,12 @@ export function write(group, {wikiData}) {
                     )}
                     <div class="grid-listing">
                         ${getAlbumGridHTML({
-                            entries: sortByDate(group.albums.map(item => ({item}))).reverse(),
+                            entries: sortChronologically(group.albums.map(album => ({
+                                item: album,
+                                directory: album.directory,
+                                name: album.name,
+                                date: album.date,
+                            }))).reverse(),
                             details: true
                         })}
                     </div>
diff --git a/src/page/track.js b/src/page/track.js
index d51cee21..04e00ee3 100644
--- a/src/page/track.js
+++ b/src/page/track.js
@@ -19,7 +19,7 @@ import {
 import {
     getTrackCover,
     getAlbumListTag,
-    sortByDate
+    sortChronologically,
 } from '../util/wiki-data.js';
 
 // Page exports
@@ -36,8 +36,15 @@ export function write(track, {wikiData}) {
 
     let flashesThatFeature;
     if (wikiInfo.enableFlashesAndGames) {
-        flashesThatFeature = sortByDate([track, ...otherReleases]
-            .flatMap(track => track.featuredInFlashes.map(flash => ({flash, as: track}))));
+        flashesThatFeature = sortChronologically([track, ...otherReleases]
+            .flatMap(track => track.featuredInFlashes
+                .map(flash => ({
+                    flash,
+                    as: track,
+                    directory: flash.directory,
+                    name: flash.name,
+                    date: flash.date
+                }))));
     }
 
     const unbound_getTrackItem = (track, {getArtistString, link, language}) => (