« get me outta code hell

content: generatePageLayout: refactor generateSidebarHTML - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-03 10:18:59 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-04-03 16:55:09 -0300
commit465c665900f1522bcc38cfd869c9587ddd1eefbd (patch)
treedaa663f30598de0c60819e5d2ed66b24ef428f1a /src/content/dependencies
parent822216b3df6525484df1b5ac436928023cc5789a (diff)
content: generatePageLayout: refactor generateSidebarHTML
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generatePageLayout.js72
1 files changed, 39 insertions, 33 deletions
diff --git a/src/content/dependencies/generatePageLayout.js b/src/content/dependencies/generatePageLayout.js
index 86a346b6..ab1323be 100644
--- a/src/content/dependencies/generatePageLayout.js
+++ b/src/content/dependencies/generatePageLayout.js
@@ -417,48 +417,54 @@ export default {
         ]);
 
     const generateSidebarHTML = (side, id) => {
-      const content = slots[side + 'Content'];
+      const attributes = html.attributes({
+        class: 'sidebar-column',
+        id,
+      });
+
       const topClass = slots[side + 'Class'];
-      const multiple = slots[side + 'Multiple'];
-      const stickyMode = slots[side + 'StickyMode'];
-      const wide = slots[side + 'Wide'];
-      const collapse = slots[side + 'Collapse'];
-
-      let sidebarClasses = [];
-      let sidebarContent = html.blank();
-
-      if (!html.isBlank(content)) {
-        sidebarClasses = ['sidebar', topClass];
-        sidebarContent = content;
-      } else if (multiple) {
-        sidebarClasses = ['sidebar-multiple', topClass];
-        sidebarContent =
-          multiple
-            .filter(Boolean)
-            .map(box =>
-              html.tag('div', {class: 'sidebar'},
-                {[html.onlyIfContent]: true},
-                {class: box.class},
-                box.content));
+      if (topClass) {
+        attributes.add('class', topClass);
       }
 
-      if (html.isBlank(sidebarContent)) {
-        return html.blank();
+      if (slots[side + 'Wide']) {
+        attributes.add('class', 'wide');
       }
 
-      return html.tag('div', {class: 'sidebar-column'},
-        {id, class: sidebarClasses},
+      if (!slots[side + 'Collapse']) {
+        attributes.add('class', 'no-hide');
+      }
 
-        wide &&
-          {class: 'wide'},
+      const stickyMode = slots[side + 'StickyMode'];
+      if (stickyMode !== 'static') {
+        attributes.add('class', `sticky-${stickyMode}`);
+      }
 
-        !collapse &&
-          {class: 'no-hide'},
+      let content = slots[side + 'Content'];
 
-        stickyMode !== 'static' &&
-          {class: `sticky-${stickyMode}`},
+      if (html.isBlank(content)) {
+        if (!slots[side + 'Multiple']) {
+          return html.blank();
+        }
+
+        const multiple =
+          slots[side + 'Multiple'].filter(Boolean);
+
+        if (empty(multiple)) {
+          return html.blank();
+        }
+
+        attributes.add('class', 'sidebar-multiple');
+        content =
+          multiple.map(box =>
+            html.tag('div', {class: 'sidebar'},
+              {class: box.class},
+              box.content));
+      } else {
+        attributes.add('class', 'sidebar');
+      }
 
-        sidebarContent);
+      return html.tag('div', attributes, content);
     }
 
     const sidebarLeftHTML = generateSidebarHTML('leftSidebar', 'sidebar-left');