« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/html.js32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 6c429b92..a6b0d621 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -56,6 +56,18 @@ export function tag(tagName, ...args) {
     throw new Error(`Tag <${tagName}> is self-closing but got content!`);
   }
 
+  if (Array.isArray(content)) {
+    if (content.some(item => Array.isArray(item))) {
+      throw new Error(`Found array instead of string (tag) or null/falsey, did you forget to \`...\` spread an array or fragment?`);
+    }
+
+    const joiner = attrs?.[joinChildren];
+    content = content.filter(Boolean).join(
+      (joiner
+        ? `\n${joiner}\n`
+        : '\n'));
+  }
+
   if (attrs?.[onlyIfContent] && !content) {
     return '';
   }
@@ -71,18 +83,6 @@ export function tag(tagName, ...args) {
     openTag = tagName;
   }
 
-  if (Array.isArray(content)) {
-    if (content.some(item => Array.isArray(item))) {
-      throw new Error(`Found array instead of string (tag) or null/falsey, did you forget to \`...\` spread an array or fragment?`);
-    }
-
-    const joiner = attrs?.[joinChildren];
-    content = content.filter(Boolean).join(
-      (joiner
-        ? `\n${joiner}\n`
-        : '\n'));
-  }
-
   if (content) {
     if (content.includes('\n')) {
       return [
@@ -102,12 +102,10 @@ export function tag(tagName, ...args) {
     } else {
       return `<${openTag}>${content}</${tagName}>`;
     }
+  } else if (selfClosing) {
+    return `<${openTag}>`;
   } else {
-    if (selfClosing) {
-      return `<${openTag}>`;
-    } else {
-      return `<${openTag}></${tagName}>`;
-    }
+    return `<${openTag}></${tagName}>`;
   }
 }