« get me outta code hell

data: Content: chop almost everything - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-11-27 15:56:40 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-11-27 15:56:40 -0400
commit3e579167d0b8c52aa31b1136aaa22aa64f11d12b (patch)
tree4c4028322ae0493d7d1967740b2b5cf17a8d5432 /src/data/things
parente4b56ce4ee3e32f0425672836af714d3e3d9912c (diff)
data: Content: chop almost everything
Diffstat (limited to 'src/data/things')
-rw-r--r--src/data/things/content.js133
1 files changed, 117 insertions, 16 deletions
diff --git a/src/data/things/content.js b/src/data/things/content.js
index 21ee88f8..49a9a0d9 100644
--- a/src/data/things/content.js
+++ b/src/data/things/content.js
@@ -1,8 +1,11 @@
 import {input} from '#composite';
+import {transposeArrays} from '#sugar';
 import Thing from '#thing';
 import {is, isDate} from '#validators';
 import {parseDate} from '#yaml';
 
+import {withFilteredList, withMappedList, withPropertyFromList}
+  from '#composite/data';
 import {contentString, simpleDate, soupyFind, thing}
   from '#composite/wiki-properties';
 
@@ -18,10 +21,7 @@ import {
 import {
   contentArtists,
   hasAnnotationPart,
-  withAnnotationParts,
-  withHasAnnotationPart,
-  withSourceText,
-  withSourceURLs,
+  withAnnotationPartNodeLists,
   withWebArchiveDate,
 } from '#composite/things/content';
 
@@ -116,21 +116,126 @@ export class ContentEntry extends Thing {
     ],
 
     annotationParts: [
-      withAnnotationParts({
-        mode: input.value('strings'),
+      withAnnotationPartNodeLists(),
+
+      {
+        dependencies: ['#annotationPartNodeLists'],
+        compute: (continuation, {
+          ['#annotationPartNodeLists']: nodeLists,
+        }) => continuation({
+          ['#firstNodes']:
+            nodeLists.map(list => list.at(0)),
+
+          ['#lastNodes']:
+            nodeLists.map(list => list.at(-1)),
+        }),
+      },
+
+      withPropertyFromList({
+        list: '#firstNodes',
+        property: input.value('i'),
+      }).outputs({
+        '#firstNodes.i': '#startIndices',
       }),
 
-      exposeDependency({dependency: '#annotationParts'}),
+      withPropertyFromList({
+        list: '#lastNodes',
+        property: input.value('iEnd'),
+      }).outputs({
+        '#lastNodes.iEnd': '#endIndices',
+      }),
+
+      {
+        dependencies: [
+          'annotation',
+          '#startIndices',
+          '#endIndices',
+        ],
+
+        compute: ({
+          ['annotation']: annotation,
+          ['#startIndices']: startIndices,
+          ['#endIndices']: endIndices,
+        }) =>
+          transposeArrays([startIndices, endIndices])
+            .map(([start, end]) =>
+              annotation.slice(start, end)),
+      },
     ],
 
     sourceText: [
-      withSourceText(),
-      exposeDependency({dependency: '#sourceText'}),
+      withAnnotationPartNodeLists(),
+
+      {
+        dependencies: ['#annotationPartNodeLists'],
+        compute: (continuation, {
+          ['#annotationPartNodeLists']: nodeLists,
+        }) => continuation({
+          ['#firstPartWithExternalLink']:
+            nodeLists
+              .find(nodes => nodes
+                .some(node => node.type === 'external-link')) ??
+            null,
+        }),
+      },
+
+      exitWithoutDependency({
+        dependency: '#firstPartWithExternalLink',
+      }),
+
+      {
+        dependencies: ['annotation', '#firstPartWithExternalLink'],
+        compute: ({
+          ['annotation']: annotation,
+          ['#firstPartWithExternalLink']: nodes,
+        }) =>
+          annotation.slice(
+            nodes.at(0).i,
+            nodes.at(-1).iEnd),
+      },
     ],
 
     sourceURLs: [
-      withSourceURLs(),
-      exposeDependency({dependency: '#sourceURLs'}),
+      withAnnotationPartNodeLists(),
+
+      {
+        dependencies: ['#annotationPartNodeLists'],
+        compute: (continuation, {
+          ['#annotationPartNodeLists']: nodeLists,
+        }) => continuation({
+          ['#firstPartWithExternalLink']:
+            nodeLists
+              .find(nodes => nodes
+                .some(node => node.type === 'external-link')) ??
+            null,
+        }),
+      },
+
+      exitWithoutDependency({
+        dependency: '#firstPartWithExternalLink',
+        value: input.value([]),
+      }),
+
+      withMappedList({
+        list: '#firstPartWithExternalLink',
+        map: input.value(node => node.type === 'external-link'),
+      }).outputs({
+        '#mappedList': '#externalLinkFilter',
+      }),
+
+      withFilteredList({
+        list: '#firstPartWithExternalLink',
+        filter: '#externalLinkFilter',
+      }),
+
+      withMappedList({
+        list: '#filteredList',
+        map: input.value(node => node.data.href),
+      }),
+
+      exposeDependency({
+        dependency: '#mappedList',
+      }),
     ],
   });
 
@@ -196,12 +301,8 @@ export class LyricsEntry extends ContentEntry {
     }),
 
     hasSquareBracketAnnotations: [
-      withHasAnnotationPart({
-        part: input.value('wiki lyrics'),
-      }),
-
       exitWithoutDependency({
-        dependency: '#hasAnnotationPart',
+        dependency: 'isWikiLyrics',
         mode: input.value('falsy'),
         value: input.value(false),
       }),