« get me outta code hell

content: generateChronologyLinksScopeSwitcher: manual blank detect - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-27 12:29:55 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-30 20:48:19 -0300
commit9b6bc1c9423dc0e355577b4922458c93114d5d89 (patch)
treece0589a5b4637352770f9906546d6e3a42aea681 /src
parent01db8ada47310c0c6994a3b950bddd0b3b0568c8 (diff)
content: generateChronologyLinksScopeSwitcher: manual blank detect
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateChronologyLinksScopeSwitcher.js80
1 files changed, 46 insertions, 34 deletions
diff --git a/src/content/dependencies/generateChronologyLinksScopeSwitcher.js b/src/content/dependencies/generateChronologyLinksScopeSwitcher.js
index 29f0c24e..23c44268 100644
--- a/src/content/dependencies/generateChronologyLinksScopeSwitcher.js
+++ b/src/content/dependencies/generateChronologyLinksScopeSwitcher.js
@@ -18,38 +18,50 @@ export default {
     },
   },
 
-  generate: (slots, {html, language}) =>
-    html.tag('details', {class: 'scoped-chronology-switcher'},
-      slots.open &&
-        {open: true},
-
-      [
-        html.tag('summary',
-          {class: 'underline-white'},
-
-          html.tag('span',
-            language.$('trackPage.nav.chronology.scope.title', {
-              scope:
-                slots.scopes.map((scope, index) =>
-                  html.tag('a', {class: 'switcher-link'},
-                    {href: '#'},
-
-                    (index === 0
-                      ? {style: 'display: inline'}
-                      : {style: 'display: none'}),
-
-                    language.$('trackPage.nav.chronology.scope', scope))),
-            }))),
-
-        stitchArrays({
-          scope: slots.scopes,
-          content: slots.contents,
-        }).map(({scope, content}, index) =>
-            html.tag('div', {class: 'scope-' + scope},
-              (index === 0
-                ? {style: 'display: block'}
-                : {style: 'display: none'}),
-
-              content)),
-      ]),
+  generate(slots, {html, language}) {
+    // TODO: Manual [html.onlyIfContent]-alike here is a bit unfortunate.
+    // We can't use a normal [html.onlyIfContent] because the summary counts
+    // as content - we'd need to encode that we want to exclude it from the
+    // content check (for the <details> element), somehow.
+    if (slots.contents.every(content => html.isBlank(content))) {
+      return html.blank();
+    }
+
+    const summary =
+      html.tag('summary',
+        {class: 'underline-white'},
+
+        html.tag('span',
+          language.$('trackPage.nav.chronology.scope.title', {
+            scope:
+              slots.scopes.map((scope, index) =>
+                html.tag('a', {class: 'switcher-link'},
+                  {href: '#'},
+
+                  (index === 0
+                    ? {style: 'display: inline'}
+                    : {style: 'display: none'}),
+
+                  language.$('trackPage.nav.chronology.scope', scope))),
+          })));
+
+    const scopeContents =
+      stitchArrays({
+        scope: slots.scopes,
+        content: slots.contents,
+      }).map(({scope, content}, index) =>
+          html.tag('div', {class: 'scope-' + scope},
+            (index === 0
+              ? {style: 'display: block'}
+              : {style: 'display: none'}),
+
+            content));
+
+    return (
+      html.tag('details', {class: 'scoped-chronology-switcher'},
+        slots.open &&
+          {open: true},
+
+        [summary, scopeContents]));
+  },
 };