« get me outta code hell

content: listTagsBy{Name,Uses} -> listArtTagsBy{Name,Uses} - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/listArtTagsByUses.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-10-08 12:42:15 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-10-10 09:41:13 -0300
commit431014efacf8bf24b58a21180e71e0db865f30fe (patch)
treeb9a05effee6dfeb456b3b527a2a3fd8b66739129 /src/content/dependencies/listArtTagsByUses.js
parent389f07982ad03bf96c50a78f46933aa1f33bf23e (diff)
content: listTagsBy{Name,Uses} -> listArtTagsBy{Name,Uses}
Diffstat (limited to 'src/content/dependencies/listArtTagsByUses.js')
-rw-r--r--src/content/dependencies/listArtTagsByUses.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/content/dependencies/listArtTagsByUses.js b/src/content/dependencies/listArtTagsByUses.js
new file mode 100644
index 00000000..9eb6f185
--- /dev/null
+++ b/src/content/dependencies/listArtTagsByUses.js
@@ -0,0 +1,54 @@
+import {stitchArrays, unique} from '#sugar';
+import {filterByCount, sortAlphabetically, sortByCount} from '#wiki-data';
+
+export default {
+  contentDependencies: ['generateListingPage', 'linkArtTagGallery'],
+  extraDependencies: ['language', 'wikiData'],
+
+  sprawl: ({artTagData}) =>
+    ({artTagData}),
+
+  query({artTagData}, spec) {
+    const artTags =
+      sortAlphabetically(
+        artTagData
+          .filter(artTag => !artTag.isContentWarning));
+
+    const counts =
+      artTags.map(artTag =>
+        unique([
+          ...artTag.directlyTaggedInThings,
+          ...artTag.indirectlyTaggedInThings,
+        ]).length);
+
+    filterByCount(artTags, counts);
+    sortByCount(artTags, counts, {greatestFirst: true});
+
+    return {spec, artTags, counts};
+  },
+
+  relations: (relation, query) => ({
+    page:
+      relation('generateListingPage', query.spec),
+
+    artTagLinks:
+      query.artTags
+        .map(artTag => relation('linkArtTagGallery', artTag)),
+  }),
+
+  data: (query) =>
+    ({counts: query.counts}),
+
+  generate: (data, relations, {language}) =>
+    relations.page.slots({
+      type: 'rows',
+      rows:
+        stitchArrays({
+          link: relations.artTagLinks,
+          count: data.counts,
+        }).map(({link, count}) => ({
+            tag: link,
+            timesUsed: language.countTimesUsed(count, {unit: true}),
+          })),
+    }),
+};