« 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.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/content/dependencies/generateCommentaryContentHeading.js b/src/content/dependencies/generateCommentaryContentHeading.js
new file mode 100644
index 00000000..92405010
--- /dev/null
+++ b/src/content/dependencies/generateCommentaryContentHeading.js
@@ -0,0 +1,33 @@
+export default {
+  contentDependencies: ['generateContentContentHeading'],
+  extraDependencies: ['language'],
+
+  relations: (relation, thing) => ({
+    contentContentHeading:
+      relation('generateContentContentHeading', thing),
+  }),
+
+  data: (thing) => ({
+    hasWikiEditorCommentary:
+      thing.commentary
+        .some(entry => entry.isWikiEditorCommentary),
+
+    onlyWikiEditorCommentary:
+      thing.commentary
+        .every(entry => entry.isWikiEditorCommentary),
+  }),
+
+  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')
+            : capsule)),
+    }),
+};