« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content/dependencies/generateArtTagGalleryPage.js26
-rw-r--r--src/content/dependencies/generateGroupGalleryPage.js11
-rw-r--r--src/content/dependencies/generateQuickDescription.js41
-rw-r--r--src/strings-default.json4
4 files changed, 59 insertions, 23 deletions
diff --git a/src/content/dependencies/generateArtTagGalleryPage.js b/src/content/dependencies/generateArtTagGalleryPage.js
index a60d1a5d..269f1b8a 100644
--- a/src/content/dependencies/generateArtTagGalleryPage.js
+++ b/src/content/dependencies/generateArtTagGalleryPage.js
@@ -5,11 +5,11 @@ export default {
   contentDependencies: [
     'generateCoverGrid',
     'generatePageLayout',
+    'generateQuickDescription',
     'image',
     'linkAlbum',
     'linkArtTag',
     'linkTrack',
-    'transformContent',
   ],
 
   extraDependencies: ['html', 'language', 'wikiData'],
@@ -46,10 +46,8 @@ export default {
     relations.infoPageLink =
       relation('linkArtTag', tag);
 
-    if (tag.descriptionShort) {
-      relations.description =
-        relation('transformContent', tag.descriptionShort);
-    }
+    relations.quickDescription =
+      relation('generateQuickDescription', tag);
 
     if (!empty(tag.directAncestorTags)) {
       relations.ancestorLinks =
@@ -86,7 +84,6 @@ export default {
 
     data.name = tag.name;
     data.color = tag.color;
-    data.hasLongerDescription = tag.descriptionShort !== tag.description;
 
     data.numArtworks = query.allThings.length;
 
@@ -120,21 +117,8 @@ export default {
 
         mainClasses: ['top-index'],
         mainContent: [
-          html.tag('p',
-            {
-              [html.joinChildren]: html.tag('br'),
-              [html.onlyIfContent]: true,
-              class:' quick-info',
-            },
-            [
-              relations.description?.slot('mode', 'inline'),
-              data.hasLongerDescription &&
-                language.$('tagPage.moreInfo', {
-                  link:
-                    relations.infoPageLink
-                      .slot('content', language.$('tagPage.moreInfo.link')),
-                }),
-            ]),
+          relations.quickDescription
+            .slot('infoPageLink', relations.infoPageLink),
 
           html.tag('p', {class: 'quick-info'},
             language.$('tagPage.infoLine', {
diff --git a/src/content/dependencies/generateGroupGalleryPage.js b/src/content/dependencies/generateGroupGalleryPage.js
index 47239f55..49869c76 100644
--- a/src/content/dependencies/generateGroupGalleryPage.js
+++ b/src/content/dependencies/generateGroupGalleryPage.js
@@ -13,8 +13,10 @@ export default {
     'generateGroupNavLinks',
     'generateGroupSidebar',
     'generatePageLayout',
+    'generateQuickDescription',
     'image',
     'linkAlbum',
+    'linkGroup',
     'linkListing',
   ],
 
@@ -70,6 +72,12 @@ export default {
           .map(album => relation('image', album.artTags));
     }
 
+    relations.quickDescription =
+      relation('generateQuickDescription', group);
+
+    relations.quickDescriptionInfoLink =
+      relation('linkGroup', group);
+
     relations.coverGrid =
       relation('generateCoverGrid');
 
@@ -143,6 +151,9 @@ export default {
                     image.slot('path', path)),
             }),
 
+          relations.quickDescription
+            .slot('infoPageLink', relations.quickDescriptionInfoLink),
+
           html.tag('p',
             {class: 'quick-info'},
             language.$('groupGalleryPage.infoLine', {
diff --git a/src/content/dependencies/generateQuickDescription.js b/src/content/dependencies/generateQuickDescription.js
new file mode 100644
index 00000000..136769ac
--- /dev/null
+++ b/src/content/dependencies/generateQuickDescription.js
@@ -0,0 +1,41 @@
+export default {
+  contentDependencies: ['transformContent'],
+  extraDependencies: ['html', 'language'],
+
+  relations: (relation, thing) =>
+    ({description:
+        (thing.descriptionShort || thing.description
+          ? relation('transformContent',
+              thing.descriptionShort ?? thing.description)
+          : null)}),
+
+  data: (thing) =>
+    ({hasLongerDescription:
+        thing.description &&
+        thing.descriptionShort &&
+        thing.descriptionShort !== thing.description}),
+
+  slots: {
+    infoPageLink: {type: 'html'},
+  },
+
+  generate(data, relations, slots, {html, language}) {
+    return html.tag('p',
+      {
+        [html.joinChildren]: html.tag('br'),
+        [html.onlyIfContent]: true,
+        class:' quick-info',
+      },
+      [
+        relations.description?.slot('mode', 'inline'),
+
+        data.hasLongerDescription &&
+        slots.infoPageLink &&
+          language.$('misc.quickDescription.moreInfo', {
+            link:
+              slots.infoPageLink
+                .slot('content', language.$('misc.quickDescription.moreInfo.link')),
+          }),
+      ]);
+  },
+};
diff --git a/src/strings-default.json b/src/strings-default.json
index 55d3b41f..a12753b0 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -205,6 +205,8 @@
   "misc.nav.gallery": "Gallery",
   "misc.pageTitle": "{TITLE}",
   "misc.pageTitle.withWikiName": "{TITLE} | {WIKI_NAME}",
+  "misc.quickDescription.moreInfo": "({LINK})",
+  "misc.quickDescription.moreInfo.link": "More info...",
   "misc.skippers.skipTo": "Skip to:",
   "misc.skippers.content": "Content",
   "misc.skippers.sidebar": "Sidebar",
@@ -499,8 +501,6 @@
   "tagPage.infoLine": "Appears in {COVER_ARTS}.",
   "tagPage.descendsFrom": "Descends from {TAGS}.",
   "tagPage.desendants": "Direct descendants: {TAGS}.",
-  "tagPage.moreInfo": "({LINK})",
-  "tagPage.moreInfo.link": "More info...",
   "tagPage.nav.tag": "Tag: {TAG}",
   "trackPage.title": "{TRACK}",
   "trackPage.referenceList.fandom": "Fandom:",