« get me outta code hell

content: generateQuickDescription: extraReadingLinks slot - 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-06-13 12:04:56 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-13 16:49:44 -0300
commit6ab0063fe64671a47beb8f15d6138c4133b31445 (patch)
treefc3ad2ef6e4e9850e6ad1346403879837d516849 /src/content/dependencies
parent63beb8dcb01f3d94fbf545bccef73495ecb07ab1 (diff)
content: generateQuickDescription: extraReadingLinks slot
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateQuickDescription.js49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/content/dependencies/generateQuickDescription.js b/src/content/dependencies/generateQuickDescription.js
index f555af28..4c7c944a 100644
--- a/src/content/dependencies/generateQuickDescription.js
+++ b/src/content/dependencies/generateQuickDescription.js
@@ -34,16 +34,40 @@ export default {
     hasLongerDescription: query.hasLongerDescription,
   }),
 
-  generate(data, relations, {html, language}) {
+  slots: {
+    extraReadingLinks: {
+      validate: v => v.sparseArrayOf(v.isHTML),
+    },
+  },
+
+  generate(data, relations, slots, {html, language}) {
     const prefix = 'misc.quickDescription';
 
+    const actionsWithoutLongerDescription =
+      (data.hasLongerDescription
+        ? null
+     : slots.extraReadingLinks
+        ? language.$(prefix, 'readMore', {
+            links:
+              language.formatDisjunctionList(slots.extraReadingLinks),
+          })
+        : null);
+
     const wrapExpandCollapseLink = (expandCollapse, content) =>
       html.tag('a', {class: `${expandCollapse}-link`},
         {href: '#'},
         content);
 
     const actionsWhenCollapsed =
-      (data.hasLongerDescription
+      (data.hasLongerDescription && slots.extraReadingLinks
+        ? language.$(prefix, 'expandDescription.orReadMore', {
+            links:
+              language.formatDisjunctionList(slots.extraReadingLinks),
+            expand:
+              wrapExpandCollapseLink('expand',
+                language.$(prefix, 'expandDescription.orReadMore.expand')),
+          })
+     : data.hasLongerDescription
         ? language.$(prefix, 'expandDescription', {
             expand:
               wrapExpandCollapseLink('expand',
@@ -52,7 +76,15 @@ export default {
         : null);
 
     const actionsWhenExpanded =
-      (data.hasLongerDescription
+      (data.hasLongerDescription && slots.extraReadingLinks
+        ? language.$(prefix, 'collapseDescription.orReadMore', {
+            links:
+              language.formatDisjunctionList(slots.extraReadingLinks),
+            collapse:
+              wrapExpandCollapseLink('collapse',
+                language.$(prefix, 'collapseDescription.orReadMore.collapse')),
+          })
+     : data.hasLongerDescription
         ? language.$(prefix, 'collapseDescription', {
             collapse:
               wrapExpandCollapseLink('collapse',
@@ -81,13 +113,22 @@ export default {
         data.hasLongerDescription &&
           {class: 'collapsed'},
 
+        !data.hasLongerDescription &&
+        !slots.extraReadingLinks &&
+          {class: 'has-content-only'},
+
+        !data.hasDescription &&
+        slots.extraReadingLinks &&
+          {class: 'has-external-links-only'},
+
         [
           wrapContent(null, relations.description),
           wrapContent({class: 'short'}, relations.descriptionShort),
           wrapContent({class: 'long'}, relations.descriptionLong),
 
+          wrapActions(null, actionsWithoutLongerDescription),
           wrapActions({class: 'when-collapsed'}, actionsWhenCollapsed),
           wrapActions({class: 'when-expanded'}, actionsWhenExpanded),
         ]));
-  }
+  },
 };