« get me outta code hell

data: add various art tag properties - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-10-02 19:05:11 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-02-25 20:03:24 -0400
commit62e08a1e06953449cb2e26c2311646d1dc010cfd (patch)
tree9f2ee4ea4bc975db854b6bcf289f33cce19e9eaf /src
parent9f681821fd4f208024a93cad7cbd20f5714680c2 (diff)
data: add various art tag properties
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/things/art-tag/index.js1
-rw-r--r--src/data/composite/things/art-tag/withAllDescendantTags.js44
-rw-r--r--src/data/things/art-tag.js40
3 files changed, 83 insertions, 2 deletions
diff --git a/src/data/composite/things/art-tag/index.js b/src/data/composite/things/art-tag/index.js
new file mode 100644
index 00000000..aedc3a0c
--- /dev/null
+++ b/src/data/composite/things/art-tag/index.js
@@ -0,0 +1 @@
+export {default as withAllDescendantTags} from './withAllDescendantTags.js';
diff --git a/src/data/composite/things/art-tag/withAllDescendantTags.js b/src/data/composite/things/art-tag/withAllDescendantTags.js
new file mode 100644
index 00000000..945e9f37
--- /dev/null
+++ b/src/data/composite/things/art-tag/withAllDescendantTags.js
@@ -0,0 +1,44 @@
+// Gets all the tags which descend from this one - that means its own direct
+// descendants, but also all the direct and indirect desceands of each of those!
+// The results aren't specially sorted, but they won't contain any duplicates
+// (for example if two descendant tags both route deeper to end up including
+// some of the same tags).
+
+import {input, templateCompositeFrom} from '#composite';
+import {unique} from '#sugar';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {withResolvedReferenceList} from '#composite/wiki-data';
+import {soupyFind} from '#composite/wiki-properties';
+
+export default templateCompositeFrom({
+  annotation: `withAllDescendantTags`,
+
+  outputs: ['#allDescendantTags'],
+
+  steps: () => [
+    raiseOutputWithoutDependency({
+      dependency: 'directDescendantTags',
+      mode: input.value('empty'),
+      output: input.value({'#allDescendantTags': []})
+    }),
+
+    withResolvedReferenceList({
+      list: 'directDescendantTags',
+      find: soupyFind.input('artTag'),
+    }),
+
+    {
+      dependencies: ['#resolvedReferenceList'],
+      compute: (continuation, {
+        ['#resolvedReferenceList']: directDescendantTags,
+      }) => continuation({
+        ['#allDescendantTags']:
+          unique([
+            ...directDescendantTags,
+            ...directDescendantTags.flatMap(tag => tag.allDescendantTags),
+          ]),
+      }),
+    },
+  ],
+})
diff --git a/src/data/things/art-tag.js b/src/data/things/art-tag.js
index 8519f7f9..9125c767 100644
--- a/src/data/things/art-tag.js
+++ b/src/data/things/art-tag.js
@@ -4,9 +4,11 @@ import {input} from '#composite';
 import find from '#find';
 import {sortAlphabetically, sortAlbumsTracksChronologically} from '#sort';
 import Thing from '#thing';
+import {unique} from '#sugar';
 import {isName} from '#validators';
 
-import {exposeUpdateValueOrContinue} from '#composite/control-flow';
+import {exitWithoutDependency, exposeDependency, exposeUpdateValueOrContinue}
+  from '#composite/control-flow';
 
 import {
   color,
@@ -14,12 +16,15 @@ import {
   flag,
   referenceList,
   reverseReferenceList,
+  simpleString,
   name,
   soupyFind,
   soupyReverse,
   wikiData,
 } from '#composite/wiki-properties';
 
+import {withAllDescendantTags} from '#composite/things/art-tag';
+
 export class ArtTag extends Thing {
   static [Thing.referenceType] = 'tag';
   static [Thing.friendlyName] = `Art Tag`;
@@ -44,6 +49,8 @@ export class ArtTag extends Thing {
       },
     ],
 
+    description: simpleString(),
+
     directDescendantTags: referenceList({
       class: input.value(ArtTag),
       find: soupyFind.input('artTag'),
@@ -56,7 +63,20 @@ export class ArtTag extends Thing {
 
     // Expose only
 
-    taggedInThings: {
+    descriptionShort: [
+      exitWithoutDependency({
+        dependency: 'description',
+        mode: input.value('falsy'),
+      }),
+
+      {
+        dependencies: ['description'],
+        compute: ({description}) =>
+          description.split('<hr class="split">')[0],
+      },
+    ],
+
+    directlyTaggedInThings: {
       flags: {expose: true},
 
       expose: {
@@ -71,6 +91,21 @@ export class ArtTag extends Thing {
       },
     },
 
+    indirectlyTaggedInThings: [
+      withAllDescendantTags(),
+
+      {
+        dependencies: ['#allDescendantTags'],
+        compute: ({'#allDescendantTags': allDescendantTags}) =>
+          unique(allDescendantTags.flatMap(tag => tag.directlyTaggedInThings)),
+      },
+    ],
+
+    allDescendantTags: [
+      withAllDescendantTags(),
+      exposeDependency({dependency: '#allDescendantTags'}),
+    ],
+
     directAncestorTags: reverseReferenceList({
       reverse: soupyReverse.input('artTagsWhichDirectlyAncestor'),
     }),
@@ -102,6 +137,7 @@ export class ArtTag extends Thing {
       'Tag': {property: 'name'},
       'Short Name': {property: 'nameShort'},
       'Directory': {property: 'directory'},
+      'Description': {property: 'description'},
 
       'Color': {property: 'color'},
       'Is CW': {property: 'isContentWarning'},