« get me outta code hell

data: #things/commentary-entry -> #things/content - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/things/content/withWebArchiveDate.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-05-01 12:43:58 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-05-06 12:29:05 -0300
commitcad44bfd247272ea8c11764d3b65dfd6a1b2b224 (patch)
treec9494dc8febb039951dc70f7ea7837c3839bda3a /src/data/composite/things/content/withWebArchiveDate.js
parent4c99ad241cd8d34c0a6a68a4edac15b869ce6ee1 (diff)
data: #things/commentary-entry -> #things/content
Diffstat (limited to 'src/data/composite/things/content/withWebArchiveDate.js')
-rw-r--r--src/data/composite/things/content/withWebArchiveDate.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/data/composite/things/content/withWebArchiveDate.js b/src/data/composite/things/content/withWebArchiveDate.js
new file mode 100644
index 00000000..3aaa4f64
--- /dev/null
+++ b/src/data/composite/things/content/withWebArchiveDate.js
@@ -0,0 +1,41 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+
+export default templateCompositeFrom({
+  annotation: `withWebArchiveDate`,
+
+  outputs: ['#webArchiveDate'],
+
+  steps: () => [
+    {
+      dependencies: ['annotation'],
+
+      compute: (continuation, {annotation}) =>
+        continuation({
+          ['#dateText']:
+            annotation
+              ?.match(/https?:\/\/web.archive.org\/web\/([0-9]{8,8})[0-9]*\//)
+              ?.[1] ??
+            null,
+        }),
+    },
+
+    raiseOutputWithoutDependency({
+      dependency: '#dateText',
+      output: input.value({['#webArchiveDate']: null}),
+    }),
+
+    {
+      dependencies: ['#dateText'],
+      compute: (continuation, {['#dateText']: dateText}) =>
+        continuation({
+          ['#webArchiveDate']:
+            new Date(
+              dateText.slice(0, 4) + '/' +
+              dateText.slice(4, 6) + '/' +
+              dateText.slice(6, 8)),
+        }),
+    },
+  ],
+});