« 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/content/dependencies/generateAlbumCommentaryPage.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/content/dependencies/generateAlbumCommentaryPage.js b/src/content/dependencies/generateAlbumCommentaryPage.js
index 4c203877..febaba19 100644
--- a/src/content/dependencies/generateAlbumCommentaryPage.js
+++ b/src/content/dependencies/generateAlbumCommentaryPage.js
@@ -1,4 +1,6 @@
-import {empty, stitchArrays} from '#sugar';
+import multilingualWordCount from 'word-count';
+
+import {accumulateSum, empty, stitchArrays} from '#sugar';
 
 export default {
   query(album) {
@@ -37,6 +39,11 @@ export default {
     relations.albumNavAccent =
       relation('generateAlbumNavAccent', album, null);
 
+    relations.bodiesForWordCount =
+      [album.commentary, ...album.tracks.map(t => t.commentary)]
+        .flat()
+        .map(entry => relation('transformContent', entry.body));
+
     if (!empty(album.commentary)) {
       relations.albumCommentaryHeading =
         relation('generateContentHeading');
@@ -155,13 +162,23 @@ export default {
                 const workingOptions = {};
 
                 if (data.entryCount >= 1) {
+                  const wordCount =
+                    accumulateSum(
+                      relations.bodiesForWordCount.flatMap(body =>
+                        multilingualWordCount(
+                          html.resolve(
+                            body.slot('mode', 'multiline'),
+                            {normalize: 'plain'}))));
+
+                  const {entryCount} = data;
+
                   workingOptions.words =
                     html.tag('b',
-                      language.formatWordCount(data.wordCount, {unit: true}));
+                      language.formatWordCount(wordCount, {unit: true}));
 
                   workingOptions.entries =
                     html.tag('b',
-                      language.countCommentaryEntries(data.entryCount, {unit: true}));
+                      language.countCommentaryEntries(entryCount, {unit: true}));
                 }
 
                 if (data.entryCount === 0) {