From ae6247c519864b4ac24d40d2af2cb2a8c4c78c17 Mon Sep 17 00:00:00 2001
From: Florrie
Date: Tue, 19 Nov 2019 21:34:28 -0400
Subject: group artist page listings by album
---
site.css | 25 ++++++++++++++
upd8-util.js | 12 +++++++
upd8.js | 104 +++++++++++++++++++++++++++++++++++------------------------
3 files changed, 98 insertions(+), 43 deletions(-)
diff --git a/site.css b/site.css
index f10af38a..bd27d169 100644
--- a/site.css
+++ b/site.css
@@ -167,3 +167,28 @@ blockquote {
p img {
max-width: 100%;
}
+
+dl dt {
+ padding-left: 2em;
+}
+
+dl dt {
+ margin-bottom: 2px;
+}
+
+dl dd {
+ margin-bottom: 1em;
+}
+
+dl {
+ counter-reset: subolcounter;
+}
+
+dl ol {
+ list-style: none;
+}
+
+dl ol li:before {
+ counter-increment: subolcounter;
+ content: counter(subolcounter) ". ";
+}
diff --git a/upd8-util.js b/upd8-util.js
index b94ffe3a..2fe2fcc8 100644
--- a/upd8-util.js
+++ b/upd8-util.js
@@ -57,3 +57,15 @@ module.exports.progressPromiseAll = function (msg, array) {
return val;
})));
};
+
+module.exports.th = function (n) {
+ if (n % 10 === 1 && n !== 11) {
+ return n + 'st';
+ } else if (n % 10 === 2 && n !== 12) {
+ return n + 'nd';
+ } else if (n % 10 === 3 && n !== 13) {
+ return n + 'rd';
+ } else {
+ return n + 'th';
+ }
+};
diff --git a/upd8.js b/upd8.js
index c2aaad31..05df1f71 100644
--- a/upd8.js
+++ b/upd8.js
@@ -78,7 +78,8 @@ const access = util.promisify(fs.access);
const {
joinNoOxford,
progressPromiseAll,
- splitArray
+ splitArray,
+ th
} = require('./upd8-util');
const SITE_TITLE = 'Homestuck Music Wiki';
@@ -704,54 +705,43 @@ async function writeArtistPage(artistName, albumData) {
].filter(Boolean).join(', ')}
${tracks.length && fixWS`
Tracks
-
- ${tracks.map(track => {
- const contrib = {
- who: artistName,
- what: [
- ...track.contributors.filter(({ who }) => who === artistName).map(({ what }) => what),
- ...getTracksReferencedBy(track, allTracks).filter(track => track.artists.includes(artistName)).map(track => `[${track.name}]`)
- ].filter(Boolean).join(', ')
- };
- if (contrib.what && track.artists.includes(artistName)) {
- const nonTracks = contrib.what.split(',').map(what => what.trim()).filter(what => !(what.startsWith('[') && what.endsWith(']')));
- contrib.what = nonTracks.join(', ');
- }
- return fixWS`
- -
- ${track.name}
- ${track.artists.includes(artistName) && track.artists.length > 1 && `(with ${getArtistString(track.artists.filter(a => a !== artistName))})`}
- ${contrib.what && `(${getContributionString(contrib, tracks) || 'contributed'})`}
- from ${track.album.name}
-
- `;
- }).join('\n')}
-
+ ${albumChunkedList(tracks, (track, i) => {
+ const contrib = {
+ who: artistName,
+ what: track.contributors.filter(({ who }) => who === artistName).map(({ what }) => what).join(', ')
+ };
+ return fixWS`
+
+ ${track.name}
+ ${track.artists.includes(artistName) && track.artists.length > 1 && `(with ${getArtistString(track.artists.filter(a => a !== artistName))})`}
+ ${contrib.what && `(${getContributionString(contrib, tracks) || 'contributed'})`}
+
+ `;
+ })}
`}
${artThings.length && fixWS`
Art
-
- ${artThings.map(thing => {
- const contrib = thing.coverArtists.find(({ who }) => who === artistName);
- return fixWS`
- -
- ${thing.name}
- ${contrib.what && `(${getContributionString(contrib, tracks)})`}
- ${thing.album ? `from ${thing.album.name}` : `(cover art)`}
-
- `;
- }).join('\n')}
-
+ ${albumChunkedList(artThings, (thing, i) => {
+ const contrib = thing.coverArtists.find(({ who }) => who === artistName);
+ return fixWS`
+
+ ${thing.album ? fixWS`
+ ${thing.name}
+ ` : '(cover art)'}
+ ${contrib.what && `(${getContributionString(contrib, tracks)})`}
+
+ `;
+ })}
`}
${commentaryThings.length && fixWS`
-
- ${commentaryThings.map(thing => fixWS`
- -
- ${thing.name}
- ${thing.album ? `from ${thing.album.name}` : `(album commentary)`}
-
- `).join('\n')}
+ ${albumChunkedList(commentaryThings, thing => fixWS`
+ -
+ ${thing.album ? fixWS`
+ ${thing.name}
+ ` : '(album commentary)'}
+
+ `, false)}
`}
@@ -760,6 +750,34 @@ async function writeArtistPage(artistName, albumData) {
`);
}
+function albumChunkedList(tracks, getLI, showDate = true) {
+ const getAlbum = thing => thing.album ? thing.album : thing;
+ return fixWS`
+
+ ${tracks.map((thing, i) => {
+ const li = getLI(thing, i);
+ const album = getAlbum(thing);
+ if (i === 0 || album !== getAlbum(tracks[i - 1]) || (showDate && +thing.date !== +tracks[i - 1].date)) {
+ const heading = fixWS`
+ -
+ ${getAlbum(thing).name}
+ ${showDate && `(${getDateString(thing)})`}
+
+
+ `;
+ if (i > 0) {
+ return ['
', heading, li];
+ } else {
+ return [heading, li];
+ }
+ } else {
+ return [li];
+ }
+ }).reduce((acc, arr) => acc.concat(arr), []).join('\n')}
+
+ `;
+}
+
// This function is terri8le. Sorry!
function getContributionString({ what }, allTracks) {
return what
--
cgit 1.3.0-6-gf8a5