« get me outta code hell

content: generateListingPage: "see also" links - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateListingPage.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-01 14:16:38 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-01 14:16:38 -0300
commit4a4617e1a92ebf70586f2420262e5e80ca15dbdc (patch)
tree188ac6af14810a7b530c693200a20232a6285e51 /src/content/dependencies/generateListingPage.js
parent2b1ffaa9696d38ed96a857f00ae2af3c13e7b08c (diff)
content: generateListingPage: "see also" links
Diffstat (limited to 'src/content/dependencies/generateListingPage.js')
-rw-r--r--src/content/dependencies/generateListingPage.js56
1 files changed, 50 insertions, 6 deletions
diff --git a/src/content/dependencies/generateListingPage.js b/src/content/dependencies/generateListingPage.js
index 6e9db68..74c90ba 100644
--- a/src/content/dependencies/generateListingPage.js
+++ b/src/content/dependencies/generateListingPage.js
@@ -1,14 +1,52 @@
+import {empty} from '../../util/sugar.js';
+
 export default {
-  contentDependencies: ['generatePageLayout', 'linkListingIndex'],
-  extraDependencies: ['html'],
+  contentDependencies: [
+    'generatePageLayout',
+    'linkListing',
+    'linkListingIndex',
+  ],
+
+  extraDependencies: ['html', 'language', 'wikiData'],
+
+  sprawl({listingSpec}) {
+    return {listingSpec};
+  },
 
-  relations(relation) {
+  query(sprawl, listing) {
     return {
-      layout: relation('generatePageLayout'),
-      listingsIndexLink: relation('linkListingIndex'),
+      seeAlso:
+        (listing.seeAlso
+          ? listing.seeAlso.map(directory =>
+              sprawl.listingSpec
+                .find(listing => listing.directory === directory))
+          : null),
     };
   },
 
+  relations(relation, query) {
+    const relations = {};
+
+    relations.layout =
+      relation('generatePageLayout');
+
+    relations.listingsIndexLink =
+      relation('linkListingIndex');
+
+    if (!empty(query.seeAlso)) {
+      // TODO: Invalid listing directories filtered here aren't warned about anywhere.
+      // Honestly we shouldn't be searching listingSpec here at all - listings should
+      // be implemented as proper things which search listingSpec themselves, and
+      // expose seeAlso as a list of listing objects rather than by reference.
+      relations.seeAlsoLinks =
+        query.seeAlso
+          .map(listing => relation('linkListing', listing))
+          .filter(Boolean);
+    }
+
+    return relations;
+  },
+
   data(query, sprawl, listing) {
     return {
       stringsKey: listing.stringsKey,
@@ -25,12 +63,18 @@ export default {
     },
   },
 
-  generate(data, relations, slots, {html}) {
+  generate(data, relations, slots, {html, language}) {
     return relations.layout.slots({
       title: language.$(`listingPage.${data.stringsKey}.title`),
       headingMode: 'sticky',
 
       mainContent: [
+        relations.seeAlsoLinks &&
+          html.tag('p',
+            language.$('listingPage.seeAlso', {
+              listings: language.formatUnitList(relations.seeAlsoLinks),
+            })),
+
         slots.type === 'rows' &&
           html.tag('ul',
             slots.rows.map(row =>