« 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/generateContentContentHeading.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateContentContentHeading.js')
-rw-r--r--src/content/dependencies/generateContentContentHeading.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/content/dependencies/generateContentContentHeading.js b/src/content/dependencies/generateContentContentHeading.js
new file mode 100644
index 00000000..9ed2d9f0
--- /dev/null
+++ b/src/content/dependencies/generateContentContentHeading.js
@@ -0,0 +1,73 @@
+export default {
+  relations: (relation, _thing) => ({
+    contentHeading:
+      relation('generateContentHeading'),
+  }),
+
+  data: (thing) => ({
+    name:
+      (thing
+        ? thing.name
+        : null),
+  }),
+
+  slots: {
+    attributes: {
+      type: 'attributes',
+      mutable: false,
+    },
+
+    string: {
+      type: 'string',
+    },
+
+    summary: {
+      type: 'boolean',
+      default: false,
+    },
+  },
+
+  generate: (data, relations, slots, {html, language}) =>
+    relations.contentHeading.slots({
+      attributes: slots.attributes,
+
+      title:
+        (() => {
+          if (!slots.string) return html.blank();
+
+          const options = {};
+
+          if (slots.summary) {
+            options.cue =
+              html.tag('span', {class: 'cue'},
+                language.$(slots.string, 'cue'));
+          }
+
+          if (data.name) {
+            options.thing = html.tag('i', data.name);
+          }
+
+          if (slots.summary) {
+            return html.tags([
+              html.tag('span', {class: 'when-open'},
+                language.$(slots.string, options)),
+
+              html.tag('span', {class: 'when-collapsed'},
+                language.$(slots.string, 'collapsed', options)),
+            ]);
+          } else {
+            return language.$(slots.string, options);
+          }
+        })(),
+
+      stickyTitle:
+        (slots.string
+          ? language.$(slots.string, 'sticky')
+          : html.blank()),
+
+      tag:
+        (slots.summary
+          ? 'summary'
+          : 'p'),
+    }),
+};