« get me outta code hell

content: generateListenLineOrList, generateReleaseInfoBlock - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateReleaseInfoBlock.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-05-01 18:37:35 -0300
committer(quasar) nebula <qznebula@protonmail.com>2026-05-01 18:37:35 -0300
commita1d39a16ab3ed60a9af4ef277fbf5c4a98a84b2d (patch)
tree5533aa908374b3575fbf1091950abde6e710a606 /src/content/dependencies/generateReleaseInfoBlock.js
parentf6aad9a81fbb1b4e619355cbec316988837fb61a (diff)
content: generateListenLineOrList, generateReleaseInfoBlock
Diffstat (limited to 'src/content/dependencies/generateReleaseInfoBlock.js')
-rw-r--r--src/content/dependencies/generateReleaseInfoBlock.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/content/dependencies/generateReleaseInfoBlock.js b/src/content/dependencies/generateReleaseInfoBlock.js
new file mode 100644
index 00000000..93d889ab
--- /dev/null
+++ b/src/content/dependencies/generateReleaseInfoBlock.js
@@ -0,0 +1,64 @@
+import {empty} from '#sugar';
+
+export default {
+  slots: {
+    // This isn't mutable, but we will be inspecting items' contents.
+    items: {validate: v => v.looseArrayOf(v.isHTML)},
+  },
+
+  generate(slots, {html}) {
+    const tags = [];
+
+    let paragraphLines = [];
+    const closeParagraph = () => {
+      if (empty(paragraphLines)) return;
+
+      const paragraph =
+        html.tag('p',
+          {[html.joinChildren]: html.tag('br')},
+          {[html.onlyIfContent]: true},
+            paragraphLines);
+
+      tags.push(paragraph);
+      paragraphLines = [];
+    };
+
+    for (let item of slots.items) {
+      item = html.Template.resolve(item);
+
+      if (typeof item === 'string' && item.length) {
+        paragraphLines.push(item);
+        continue;
+      }
+
+      if (html.isBlank(item)) {
+        continue;
+      }
+
+      if (item.contentOnly) {
+        paragraphLines.push(item);
+        continue;
+      }
+
+      if (item.tagName === 'br') {
+        continue;
+      }
+
+      if (item.tagName === 'p') {
+        paragraphLines.push(item.content);
+        continue;
+      }
+
+      closeParagraph();
+      tags.push(item);
+    }
+
+    closeParagraph();
+
+    if (empty(tags)) {
+      return html.blank();
+    } else {
+      return html.tags(tags);
+    }
+  }
+};