« get me outta code hell

content: generateArtistInfoPage: total duration paragraph - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-06-03 14:34:15 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-03 14:34:15 -0300
commitbfe08bc930c8b19bb440f668692acaf72d562be5 (patch)
treeff59b94af8215b890d40967474553aa03acfe818 /src
parent3454d3e276342e99351bad0bdbf3521c694940ab (diff)
content: generateArtistInfoPage: total duration paragraph
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateArtistInfoPage.js48
1 files changed, 23 insertions, 25 deletions
diff --git a/src/content/dependencies/generateArtistInfoPage.js b/src/content/dependencies/generateArtistInfoPage.js
index 8cddfe44..73fc8711 100644
--- a/src/content/dependencies/generateArtistInfoPage.js
+++ b/src/content/dependencies/generateArtistInfoPage.js
@@ -1,12 +1,8 @@
-import {
-  accumulateSum,
-  empty,
-  filterProperties,
-  unique,
-} from '../../util/sugar.js';
+import {empty, filterProperties, unique} from '../../util/sugar.js';
 
 import {
   chunkByProperties,
+  getTotalDuration,
   sortAlbumsTracksChronologically,
 } from '../../util/wiki-data.js';
 
@@ -113,7 +109,7 @@ export default {
         .map(({album, date, chunk}) => ({
           albumLink: relation('linkAlbum', album),
           date: +date,
-          duration: accumulateSum(chunk.map(track => track.duration)),
+          duration: getTotalDuration(chunk),
           entries: chunk
             .map(entry =>
               filterProperties(entry, [
@@ -248,9 +244,15 @@ export default {
   },
 
   data(artist) {
-    return {
-      name: artist.name,
-    };
+    const data = {};
+
+    data.name = artist.name;
+
+    const allTracks = unique([...artist.tracksAsArtist, ...artist.tracksAsContributor]);
+    data.totalTrackCount = allTracks.length;
+    data.totalDuration = getTotalDuration(allTracks, {originalReleasesOnly: true});
+
+    return data;
   },
 
   generate(data, relations, {html, language}) {
@@ -325,6 +327,17 @@ export default {
                 title: language.$('artistPage.trackList.title'),
               }),
 
+            data.totalDuration > 0 &&
+              html.tag('p',
+                language.$('artistPage.contributedDurationLine', {
+                  artist: data.name,
+                  duration:
+                    language.formatDuration(data.totalDuration, {
+                      approximate: data.totalTrackCount > 1,
+                      unit: true,
+                    }),
+                })),
+
             html.tag('dl',
               sec.tracks.chunks.map(({albumLink, date, duration, entries}) => [
                 html.tag('dt',
@@ -464,8 +477,6 @@ export function write(artist, {wikiData}) {
     key,
   });
 
-  const totalDuration = getTotalDuration(allTracks.filter(t => !t.originalReleaseTrack));
-
   const countGroups = (things) => {
     const usedGroups = things.flatMap(
       (thing) => thing.groups || thing.album?.groups || []);
@@ -730,19 +741,6 @@ export function write(artist, {wikiData}) {
                   {id: 'tracks', class: ['content-heading']},
                   language.$('artistPage.trackList.title')),
 
-                totalDuration > 0 &&
-                  html.tag('p',
-                    language.$('artistPage.contributedDurationLine', {
-                      artist: artist.name,
-                      duration: language.formatDuration(
-                        totalDuration,
-                        {
-                          approximate: true,
-                          unit: true,
-                        }
-                      ),
-                    })),
-
                 !empty(musicGroups) &&
                   html.tag('p',
                     language.$('artistPage.musicGroupsLine', {