« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/listing-spec.js52
-rw-r--r--src/page/listing.js14
-rwxr-xr-xsrc/upd8.js3
-rw-r--r--src/util/magic-constants.js1
-rw-r--r--src/util/wiki-data.js4
5 files changed, 27 insertions, 47 deletions
diff --git a/src/listing-spec.js b/src/listing-spec.js
index 6bfc871c..f1e39163 100644
--- a/src/listing-spec.js
+++ b/src/listing-spec.js
@@ -1,10 +1,6 @@
 import fixWS from 'fix-whitespace';
 
 import {
-    UNRELEASED_TRACKS_DIRECTORY
-} from './util/magic-constants.js';
-
-import {
     chunkByProperties,
     getArtistNumContributions,
     getTotalDuration,
@@ -70,8 +66,7 @@ const listingSpec = [
         stringsKey: 'listAlbums.byDate',
 
         data({wikiData}) {
-            return sortByDate(wikiData.albumData
-                .filter(album => album.directory !== UNRELEASED_TRACKS_DIRECTORY));
+            return sortByDate(wikiData.albumData.filter(album => album.date));
         },
 
         row(album, {link, strings}) {
@@ -240,7 +235,7 @@ const listingSpec = [
                     duration: getTotalDuration([
                         ...artist.tracksAsArtist ?? [],
                         ...artist.tracksAsContributor ?? []
-                    ].filter(track => track.album.directory !== UNRELEASED_TRACKS_DIRECTORY))
+                    ])
                 }))
                 .filter(({ duration }) => duration > 0)
                 .sort((a, b) => b.duration - a.duration);
@@ -259,35 +254,27 @@ const listingSpec = [
         stringsKey: 'listArtists.byLatest',
 
         data({wikiData}) {
-            const reversedTracks = wikiData.trackData.slice().reverse();
-            const reversedArtThings = wikiData.justEverythingSortedByArtDateMan.slice().reverse();
+            const reversedTracks = wikiData.trackData.filter(t => t.date).reverse();
+            const reversedArtThings = wikiData.justEverythingSortedByArtDateMan.filter(t => t.date).reverse();
 
             return {
                 toTracks: sortByDate(wikiData.artistData
-                    .filter(artist => !artist.alias)
                     .map(artist => ({
                         artist,
-                        date: reversedTracks.find(track => (
-                            track.album?.directory !== UNRELEASED_TRACKS_DIRECTORY &&
-                            [
-                                ...track.artistContribs ?? [],
-                                ...track.contributorContribs ?? []
-                            ].some(({ who }) => who === artist)
-                        ))?.date
+                        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(),
 
                 toArtAndFlashes: sortByDate(wikiData.artistData
-                    .filter(artist => !artist.alias)
                     .map(artist => {
-                        const thing = reversedArtThings.find(thing => (
-                            thing.album?.directory !== UNRELEASED_TRACKS_DIRECTORY &&
-                            [
-                                ...thing.coverArtistContribs ?? [],
-                                ...!thing.album && thing.contributorContribs || []
-                            ].some(({ who }) => who === artist)
-                        ));
+                        const thing = reversedArtThings.find(thing => ([
+                            ...thing.coverArtistContribs ?? [],
+                            ...!thing.album && thing.contributorContribs || []
+                        ].some(({ who }) => who === artist)));
                         return thing && {
                             artist,
                             date: (thing.coverArtistContribs?.some(({ who }) => who === artist)
@@ -451,7 +438,14 @@ const listingSpec = [
 
         data({wikiData}) {
             return sortByDate(wikiData.groupData
-                .map(group => ({group, date: group.albums[group.albums.length - 1]?.date}))
+                .map(group => {
+                    const albums = group.albums.filter(a => a.date);
+                    return albums.length && {
+                        group,
+                        date: albums[albums.length - 1].date
+                    };
+                })
+                .filter(Boolean)
                 // So this is kinda tough to explain, 8ut 8asically, when we
                 // reverse the list after sorting it 8y d8te (so that the latest
                 // d8tes come first), it also flips the order of groups which
@@ -522,7 +516,7 @@ const listingSpec = [
 
         data({wikiData}) {
             return chunkByProperties(
-                sortByDate(wikiData.trackData.filter(track => track.album.directory !== UNRELEASED_TRACKS_DIRECTORY)),
+                sortByDate(wikiData.trackData.filter(t => t.date)),
                 ['album', 'date']
             );
         },
@@ -558,7 +552,6 @@ const listingSpec = [
 
         data({wikiData}) {
             return wikiData.trackData
-                .filter(track => track.album.directory !== UNRELEASED_TRACKS_DIRECTORY)
                 .map(track => ({track, duration: track.duration}))
                 .filter(({ duration }) => duration > 0)
                 .sort((a, b) => b.duration - a.duration);
@@ -631,8 +624,7 @@ const listingSpec = [
 
         data({wikiData}) {
             return chunkByProperties(wikiData.trackData
-                .filter(t => t.featuredInFlashes?.length > 0), ['album'])
-                .filter(({ album }) => album.directory !== UNRELEASED_TRACKS_DIRECTORY);
+                .filter(t => t.featuredInFlashes?.length > 0), ['album']);
         },
 
         html(chunks, {link, strings}) {
diff --git a/src/page/listing.js b/src/page/listing.js
index 3083a599..8a6d3526 100644
--- a/src/page/listing.js
+++ b/src/page/listing.js
@@ -15,10 +15,6 @@ import fixWS from 'fix-whitespace';
 import * as html from '../util/html.js';
 
 import {
-    UNRELEASED_TRACKS_DIRECTORY
-} from '../util/magic-constants.js';
-
-import {
     getTotalDuration
 } from '../util/wiki-data.js';
 
@@ -99,9 +95,7 @@ export function write(listing, {wikiData}) {
 export function writeTargetless({wikiData}) {
     const { albumData, trackData, wikiInfo } = wikiData;
 
-    const releasedTracks = trackData.filter(track => track.album.directory !== UNRELEASED_TRACKS_DIRECTORY);
-    const releasedAlbums = albumData.filter(album => album.directory !== UNRELEASED_TRACKS_DIRECTORY);
-    const duration = getTotalDuration(releasedTracks);
+    const totalDuration = getTotalDuration(trackData);
 
     const page = {
         type: 'page',
@@ -118,9 +112,9 @@ export function writeTargetless({wikiData}) {
                     <h1>${strings('listingIndex.title')}</h1>
                     <p>${strings('listingIndex.infoLine', {
                         wiki: wikiInfo.name,
-                        tracks: `<b>${strings.count.tracks(releasedTracks.length, {unit: true})}</b>`,
-                        albums: `<b>${strings.count.albums(releasedAlbums.length, {unit: true})}</b>`,
-                        duration: `<b>${strings.count.duration(duration, {approximate: true, unit: true})}</b>`
+                        tracks: `<b>${strings.count.tracks(trackData.length, {unit: true})}</b>`,
+                        albums: `<b>${strings.count.albums(albumData.length, {unit: true})}</b>`,
+                        duration: `<b>${strings.count.duration(totalDuration, {approximate: true, unit: true})}</b>`
                     })}</p>
                     <hr>
                     <p>${strings('listingIndex.exploreList')}</p>
diff --git a/src/upd8.js b/src/upd8.js
index 13cf2e77..33c40677 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -170,8 +170,7 @@ import {
 // Pensive emoji!
 import {
     FANDOM_GROUP_DIRECTORY,
-    OFFICIAL_GROUP_DIRECTORY,
-    UNRELEASED_TRACKS_DIRECTORY
+    OFFICIAL_GROUP_DIRECTORY
 } from './util/magic-constants.js';
 
 const __dirname = path.dirname(fileURLToPath(import.meta.url));
diff --git a/src/util/magic-constants.js b/src/util/magic-constants.js
index 3174daec..73fdbc6d 100644
--- a/src/util/magic-constants.js
+++ b/src/util/magic-constants.js
@@ -6,6 +6,5 @@
 // All such uses should eventually be replaced with better code in due time
 // (TM).
 
-export const UNRELEASED_TRACKS_DIRECTORY = 'unreleased-tracks';
 export const OFFICIAL_GROUP_DIRECTORY = 'official';
 export const FANDOM_GROUP_DIRECTORY = 'fandom';
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js
index 6d0db2c7..b4f7f210 100644
--- a/src/util/wiki-data.js
+++ b/src/util/wiki-data.js
@@ -1,9 +1,5 @@
 // Utility functions for interacting with wiki data.
 
-import {
-    UNRELEASED_TRACKS_DIRECTORY
-} from './magic-constants.js';
-
 // Generic value operations
 
 export function getKebabCase(name) {