diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-10-02 19:05:11 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-10-02 19:05:11 -0300 |
commit | 161db8862cef023f5076c4495e48202d54d8b84a (patch) | |
tree | 4857db59f95b7159817e49fe93b72cfa5b20ecd9 | |
parent | 83892033efd40cb4baebe10718930d856b56254d (diff) |
data: add various art tag properties
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/data/composite/things/art-tag/index.js | 1 | ||||
-rw-r--r-- | src/data/composite/things/art-tag/withAllDescendantTags.js | 45 | ||||
-rw-r--r-- | src/data/things/art-tag.js | 39 | ||||
-rw-r--r-- | src/data/yaml.js | 1 |
5 files changed, 85 insertions, 2 deletions
diff --git a/package.json b/package.json index 16261f92..260037ee 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "#composite/wiki-data": "./src/data/composite/wiki-data/index.js", "#composite/wiki-properties": "./src/data/composite/wiki-properties/index.js", "#composite/things/album": "./src/data/composite/things/album/index.js", + "#composite/things/art-tag": "./src/data/composite/things/art-tag/index.js", "#composite/things/track": "./src/data/composite/things/track/index.js", "#content-dependencies": "./src/content/dependencies/index.js", "#content-function": "./src/content-function.js", 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..b832e529 --- /dev/null +++ b/src/data/composite/things/art-tag/withAllDescendantTags.js @@ -0,0 +1,45 @@ +// 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 find from '#find'; +import {unique} from '#sugar'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; +import {withResolvedReferenceList} from '#composite/wiki-data'; + +export default templateCompositeFrom({ + annotation: `withAllDescendantTags`, + + outputs: ['#allDescendantTags'], + + steps: () => [ + raiseOutputWithoutDependency({ + dependency: 'directDescendantTags', + mode: input.value('empty'), + output: input.value({'#allDescendantTags': []}) + }), + + withResolvedReferenceList({ + list: 'directDescendantTags', + data: 'artTagData', + find: input.value(find.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 f6798214..d86800de 100644 --- a/src/data/things/art-tag.js +++ b/src/data/things/art-tag.js @@ -1,9 +1,11 @@ import {input} from '#composite'; import find from '#find'; +import {unique} from '#sugar'; import {isName} from '#validators'; import {sortAlbumsTracksChronologically} from '#wiki-data'; -import {exposeUpdateValueOrContinue} from '#composite/control-flow'; +import {exitWithoutDependency, exposeDependency, exposeUpdateValueOrContinue} + from '#composite/control-flow'; import { color, @@ -11,10 +13,13 @@ import { flag, referenceList, reverseReferenceList, + simpleString, name, wikiData, } from '#composite/wiki-properties'; +import {withAllDescendantTags} from '#composite/things/art-tag'; + import Thing from './thing.js'; export class ArtTag extends Thing { @@ -40,6 +45,8 @@ export class ArtTag extends Thing { }, ], + description: simpleString(), + directDescendantTags: referenceList({ class: input.value(ArtTag), find: input.value(find.artTag), @@ -54,7 +61,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: { @@ -67,6 +87,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({ data: 'artTagData', list: input.value('directDescendantTags'), diff --git a/src/data/yaml.js b/src/data/yaml.js index 8a5cb2ca..c8916fb8 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -459,6 +459,7 @@ export const processArtTagDocument = makeProcessDocument(T.ArtTag, { name: 'Tag', nameShort: 'Short Name', directory: 'Directory', + description: 'Description', color: 'Color', isContentWarning: 'Is CW', |