« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/getContentEntryTotals.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/getContentEntryTotals.js')
-rw-r--r--src/content/dependencies/getContentEntryTotals.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/content/dependencies/getContentEntryTotals.js b/src/content/dependencies/getContentEntryTotals.js
new file mode 100644
index 00000000..ce590887
--- /dev/null
+++ b/src/content/dependencies/getContentEntryTotals.js
@@ -0,0 +1,29 @@
+import multilingualWordCount from 'word-count';
+
+import {accumulateSum} from '#sugar';
+
+export default {
+  relations: (relation, entries) => ({
+    bodies:
+      entries
+        .map(entry => relation('transformContent', entry.body)),
+  }),
+
+  data: (entries) => ({
+    entries:
+      entries.length,
+  }),
+
+  generate: (data, relations, {html}) => ({
+    entryCount:
+      data.entries,
+
+    wordCount:
+      accumulateSum(
+        relations.bodies.flatMap(body =>
+          multilingualWordCount(
+            html.resolve(
+              body.slot('mode', 'multiline'),
+              {normalize: 'plain'})))),
+  }),
+};
\ No newline at end of file