From 531219642b93a5dc236f217d22f024fb2707191f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 10 Jun 2022 17:07:01 -0300 Subject: various sorting improvements across the board MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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" --- src/misc-templates.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/misc-templates.js') diff --git a/src/misc-templates.js b/src/misc-templates.js index f40229d..c337f6e 100644 --- a/src/misc-templates.js +++ b/src/misc-templates.js @@ -6,6 +6,11 @@ import fixWS from 'fix-whitespace'; import * as html from './util/html.js'; +import { + Track, + Album, +} from './data/things.js'; + import { getColors } from './util/colors.js'; @@ -16,7 +21,8 @@ import { import { getTotalDuration, - sortByDate + sortAlbumsTracksChronologically, + sortChronologically, } from './util/wiki-data.js'; const BANDCAMP_DOMAINS = [ @@ -112,7 +118,15 @@ export function generateChronologyLinks(currentThing, { } return contributions.map(({ who: artist }) => { - const things = sortByDate(unique(getThings(artist)).filter(t => t[dateKey]), dateKey); + const thingsUnsorted = unique(getThings(artist)).filter(t => t[dateKey]); + + // Kinda a hack, but we automatically detect which is (probably) the + // right function to use here. + const args = [thingsUnsorted, {getDate: t => t[dateKey]}]; + const things = (thingsUnsorted.every(t => t instanceof Album || t instanceof Track) + ? sortAlbumsTracksChronologically(...args) + : sortChronologically(...args)); + const index = things.indexOf(currentThing); if (index === -1) return ''; -- cgit 1.3.0-6-gf8a5