« 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/generateCommentaryContentHeading.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateCommentaryContentHeading.js')
-rw-r--r--src/content/dependencies/generateCommentaryContentHeading.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/content/dependencies/generateCommentaryContentHeading.js b/src/content/dependencies/generateCommentaryContentHeading.js
new file mode 100644
index 00000000..691762aa
--- /dev/null
+++ b/src/content/dependencies/generateCommentaryContentHeading.js
@@ -0,0 +1,43 @@
+import {empty} from '#sugar';
+
+export default {
+  query: (thing) => ({
+    entries:
+      (thing.isTrack
+        ? [...thing.commentary, ...thing.commentaryFromMainRelease]
+        : thing.commentary),
+  }),
+
+  relations: (relation, _query, thing) => ({
+    contentContentHeading:
+      relation('generateContentContentHeading', thing),
+  }),
+
+  data: (query, _thing) => ({
+    hasWikiEditorCommentary:
+      query.entries.some(entry => entry.isWikiEditorCommentary),
+
+    onlyWikiEditorCommentary:
+      !empty(query.entries) &&
+      query.entries.every(entry => entry.isWikiEditorCommentary),
+
+    hasAnyCommentary:
+      !empty(query.entries),
+  }),
+
+  generate: (data, relations, {language}) =>
+    relations.contentContentHeading.slots({
+      // It's #artist-commentary for legacy reasons... Sorry...
+      attributes: {id: 'artist-commentary'},
+
+      string:
+        language.encapsulate('misc.artistCommentary', capsule =>
+          (data.onlyWikiEditorCommentary
+            ? language.encapsulate(capsule, 'onlyWikiCommentary')
+         : data.hasWikiEditorCommentary
+            ? language.encapsulate(capsule, 'withWikiCommentary')
+         : data.hasAnyCommentary
+            ? capsule
+            : null)),
+    }),
+};