« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/listTagsByName.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/listTagsByName.js')
-rw-r--r--src/content/dependencies/listTagsByName.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/content/dependencies/listTagsByName.js b/src/content/dependencies/listTagsByName.js
new file mode 100644
index 0000000..d7022a5
--- /dev/null
+++ b/src/content/dependencies/listTagsByName.js
@@ -0,0 +1,54 @@
+import {sortAlphabetically} from '#sort';
+import {stitchArrays} from '#sugar';
+
+export default {
+  contentDependencies: ['generateListingPage', 'linkArtTag'],
+  extraDependencies: ['language', 'wikiData'],
+
+  sprawl({artTagData}) {
+    return {artTagData};
+  },
+
+  query({artTagData}, spec) {
+    return {
+      spec,
+
+      artTags:
+        sortAlphabetically(
+          artTagData
+            .filter(tag => !tag.isContentWarning)),
+    };
+  },
+
+  relations(relation, query) {
+    return {
+      page: relation('generateListingPage', query.spec),
+
+      artTagLinks:
+        query.artTags
+          .map(tag => relation('linkArtTag', tag)),
+    };
+  },
+
+  data(query) {
+    return {
+      counts:
+        query.artTags
+          .map(tag => tag.taggedInThings.length),
+    };
+  },
+
+  generate(data, relations, {language}) {
+    return relations.page.slots({
+      type: 'rows',
+      rows:
+        stitchArrays({
+          link: relations.artTagLinks,
+          count: data.counts,
+        }).map(({link, count}) => ({
+            tag: link,
+            timesUsed: language.countTimesUsed(count, {unit: true}),
+          })),
+    });
+  },
+};