« get me outta code hell

don't duplic8 contrib&artist trax on artist pages! - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-02-07 11:05:50 -0400
committer(quasar) nebula <towerofnix@gmail.com>2021-02-07 11:05:50 -0400
commit1322f423ffcb76ce532ce584b138d648d6b0df95 (patch)
tree37f88908f715eae7f73c2422aaf098dd015fb7b8
parent5fcbce1f9e62c780e1ac3fe6161e4a70ba09d86a (diff)
don't duplic8 contrib&artist trax on artist pages!
if an artist is both an artist and contributor for a track, that track
would show up twice on the artist page, and with the exact same line,
due to the way the artist track list is constructed. this started
happening because we combine the "as contributor" and "as artist" arrays
for a given artist, which can have overlap! so now we throw a unique()
utility function on top and it works like its supposed to.
-rw-r--r--upd8-util.js2
-rwxr-xr-xupd8.js11
2 files changed, 8 insertions, 5 deletions
diff --git a/upd8-util.js b/upd8-util.js
index a266efbd..b18c0529 100644
--- a/upd8-util.js
+++ b/upd8-util.js
@@ -304,3 +304,5 @@ module.exports.curry = f => x => (...args) => f(x, ...args);
 module.exports.mapInPlace = (array, fn) => array.splice(0, array.length, ...array.map(fn));
 
 module.exports.filterEmptyLines = string => string.split('\n').filter(line => line.trim()).join('\n');
+
+module.exports.unique = arr => Array.from(new Set(arr));
diff --git a/upd8.js b/upd8.js
index 11c8ad0e..130f6067 100755
--- a/upd8.js
+++ b/upd8.js
@@ -114,7 +114,8 @@ const {
     queue,
     s,
     splitArray,
-    th
+    th,
+    unique
 } = require('./upd8-util');
 
 const C = require('./common/common');
@@ -2311,18 +2312,18 @@ async function writeArtistPage(artist) {
         note = ''
     } = artist;
 
-    const artThingsAll = C.sortByDate(Array.from(new Set([...artist.tracks.asCoverArtist, ...artist.albums.asCoverArtist, ...artist.albums.asWallpaperArtist])));
+    const artThingsAll = C.sortByDate(unique([...artist.tracks.asCoverArtist, ...artist.albums.asCoverArtist, ...artist.albums.asWallpaperArtist]));
     const artThingsGallery = C.sortByDate([...artist.albums.asCoverArtist, ...artist.tracks.asCoverArtist]);
-    const commentaryThings = C.sortByDate([...artist.tracks.asCommentator, ...artist.albums.asCommentator]);
+    const commentaryThings = C.sortByDate([...artist.albums.asCommentator, ...artist.tracks.asCommentator]);
 
     let flashes;
     if (wikiInfo.features.flashesAndGames) {
         flashes = artist.flashes.asContributor;
     }
 
-    const unreleasedTracks = [...artist.tracks.asArtist, ...artist.tracks.asContributor]
+    const unreleasedTracks = unique([...artist.tracks.asArtist, ...artist.tracks.asContributor])
         .filter(track => track.album.directory === C.UNRELEASED_TRACKS_DIRECTORY);
-    const releasedTracks = [...artist.tracks.asArtist, ...artist.tracks.asContributor]
+    const releasedTracks = unique([...artist.tracks.asArtist, ...artist.tracks.asContributor])
         .filter(track => track.album.directory !== C.UNRELEASED_TRACKS_DIRECTORY);
 
     const generateTrackList = tracks => albumChunkedList(tracks, (track, i) => {