« get me outta code hell

content: generateArtTagInfoPage: descendant gallery links - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-10-06 00:55:16 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-10-06 00:55:16 -0300
commite327490387c97c79fd63abc88cfee115679499ac (patch)
tree3943bf66358451fa7b92d850dfdc833efaf869e3
parent5285c0c896e89314e961b0f6261bc9bcda2813bd (diff)
content: generateArtTagInfoPage: descendant gallery links
-rw-r--r--src/content/dependencies/generateArtTagInfoPage.js46
-rw-r--r--src/strings-default.json6
2 files changed, 45 insertions, 7 deletions
diff --git a/src/content/dependencies/generateArtTagInfoPage.js b/src/content/dependencies/generateArtTagInfoPage.js
index be25cd9..056d974 100644
--- a/src/content/dependencies/generateArtTagInfoPage.js
+++ b/src/content/dependencies/generateArtTagInfoPage.js
@@ -1,4 +1,4 @@
-import {empty, unique} from '#sugar';
+import {empty, stitchArrays, unique} from '#sugar';
 
 export default {
   contentDependencies: [
@@ -76,9 +76,19 @@ export default {
       descendants.heading =
         relation('generateContentHeading');
 
-      descendants.directDescendantLinks =
+      descendants.directDescendantInfoLinks =
         artTag.directDescendantArtTags
           .map(artTag => relation('linkArtTagInfo', artTag));
+
+      const allDescendantsHaveMoreDescendants =
+        artTag.directDescendantArtTags
+          .every(artTag => !empty(artTag.directDescendantArtTags));
+
+      if (!allDescendantsHaveMoreDescendants) {
+        descendants.directDescendantGalleryLinks =
+          artTag.directDescendantArtTags
+            .map(artTag => relation('linkArtTagGallery', artTag));
+      }
     }
 
     return relations;
@@ -167,7 +177,11 @@ export default {
 
             html.tag('ul',
               sec.ancestors.directAncestorLinks
-                .map(link => html.tag('li', link))),
+                .map(link =>
+                  html.tag('li',
+                    language.$('artTagInfoPage.descendsFromTags.item', {
+                      tag: link,
+                    })))),
           ],
 
           sec.descendants && [
@@ -175,9 +189,29 @@ export default {
               .slot('title',
                 language.$('artTagInfoPage.descendantTags', nameOption)),
 
-            html.tag('ul',
-              sec.descendants.directDescendantLinks
-                .map(link => html.tag('li', link))),
+            !sec.descendants.directDescendantGalleryLinks &&
+              html.tag('ul',
+                sec.descendants.directDescendantInfoLinks
+                  .map(link =>
+                    html.tag('li',
+                      language.$('artTagInfoPage.descendantTags.item', {
+                        tag: link,
+                      })))),
+
+            sec.descendants.directDescendantGalleryLinks &&
+              html.tag('ul',
+                stitchArrays({
+                  infoLink: sec.descendants.directDescendantInfoLinks,
+                  galleryLink: sec.descendants.directDescendantGalleryLinks,
+                }).map(({infoLink, galleryLink}) =>
+                    html.tag('li',
+                      language.$('artTagInfoPage.descendantTags.item.withGallery', {
+                        tag: infoLink,
+
+                        gallery:
+                          galleryLink.slot('content',
+                            language.$('artTagInfoPage.descendantTags.item.gallery')),
+                      })))),
           ],
         ],
 
diff --git a/src/strings-default.json b/src/strings-default.json
index be8939b..f12fbad 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -336,8 +336,12 @@
   "artTagInfoPage.featuredIn.directlyOnly": "This tag is featured in {ARTWORKS}.",
   "artTagInfoPage.featuredIn.indirectlyOnly": "This tag is featured in {ARTWORKS}, but only indirectly - have a look at its descendant tags!",
   "artTagInfoPage.featuredIn.directlyAndIndirectly": "This tag is directly featured in {ARTWORKS_DIRECTLY}, and indirectly in {ARTWORKS_INDIRECTLY} more, for a total of {ARTWORKS_TOTAL}.",
-  "artTagInfoPage.descendantTags": "Tags that descend from {TAG}:",
   "artTagInfoPage.descendsFromTags": "Tags that {TAG} descends from:",
+  "artTagInfoPage.descendsFromTags.item": "{TAG}",
+  "artTagInfoPage.descendantTags": "Tags that descend from {TAG}:",
+  "artTagInfoPage.descendantTags.item": "{TAG}",
+  "artTagInfoPage.descendantTags.item.withGallery": "{TAG} ({GALLERY})",
+  "artTagInfoPage.descendantTags.item.gallery": "Gallery",
   "artTagGalleryPage.title": "{TAG}",
   "artTagGalleryPage.infoLine": "Appears in {COVER_ARTS}.",
   "artTagGalleryPage.descendsFrom": "Descends from {TAGS}.",