« get me outta code hell

content: listTagsBy{Name,Uses} - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-16 13:37:15 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-16 13:37:15 -0300
commitfa57fb3e3a0fd628e134fbe25102cbc3aa8a1c70 (patch)
tree41173ff122f47872bbffd592aedbd8904544ca7a /src/content
parentc5a341835898219602c7f2237f9ddfa7f749ceeb (diff)
content: listTagsBy{Name,Uses}
Diffstat (limited to 'src/content')
-rw-r--r--src/content/dependencies/listArtistsByName.js2
-rw-r--r--src/content/dependencies/listTagsByName.js54
-rw-r--r--src/content/dependencies/listTagsByUses.js53
3 files changed, 108 insertions, 1 deletions
diff --git a/src/content/dependencies/listArtistsByName.js b/src/content/dependencies/listArtistsByName.js
index 1b93eca8..4b379bb2 100644
--- a/src/content/dependencies/listArtistsByName.js
+++ b/src/content/dependencies/listArtistsByName.js
@@ -27,7 +27,7 @@ export default {
 
       artistLinks:
         query.artists
-          .map(album => relation('linkArtist', album)),
+          .map(artist => relation('linkArtist', artist)),
     };
   },
 
diff --git a/src/content/dependencies/listTagsByName.js b/src/content/dependencies/listTagsByName.js
new file mode 100644
index 00000000..b5aa172f
--- /dev/null
+++ b/src/content/dependencies/listTagsByName.js
@@ -0,0 +1,54 @@
+import {stitchArrays} from '../../util/sugar.js';
+import {sortAlphabetically} from '../../util/wiki-data.js';
+
+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}),
+          })),
+    });
+  },
+};
diff --git a/src/content/dependencies/listTagsByUses.js b/src/content/dependencies/listTagsByUses.js
new file mode 100644
index 00000000..81b66424
--- /dev/null
+++ b/src/content/dependencies/listTagsByUses.js
@@ -0,0 +1,53 @@
+import {stitchArrays} from '../../util/sugar.js';
+import {filterByCount, sortByCount} from '../../util/wiki-data.js';
+
+export default {
+  contentDependencies: ['generateListingPage', 'linkArtTag'],
+  extraDependencies: ['language', 'wikiData'],
+
+  sprawl({artTagData}) {
+    return {artTagData};
+  },
+
+  query({artTagData}, spec) {
+    const artTags = artTagData.filter(tag => !tag.isContentWarning);
+    const counts = artTags.map(tag => tag.taggedInThings.length);
+
+    filterByCount(artTags, counts);
+    sortByCount(artTags, counts, {greatestFirst: true});
+
+    return {spec, artTags, counts};
+  },
+
+  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}),
+          })),
+    });
+  },
+};