« 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-18 22:56:11 -0300
commit7c2d3127fda234fe1abd8705a7dbe544fea60daa (patch)
treee778e3ef62bcb6fe71e94c0604955446e785b957 /src/content/dependencies
parent194e6e9f6cb837c57f8317abe3394714ca8faa32 (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),
         ]));
-  }
+  },
 };