« get me outta code hell

data: withParsedCommentaryEntries: auto-fill archive capture dates - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-21 10:45:23 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-21 10:47:46 -0300
commit5a68a93b5264f9058a94e3ecb16366d596e1a153 (patch)
treeb9b79d69edd9b8d92d76e29346b9ecab5e6e4e42
parent4d040ff96841366cb024171de80751da448d7254 (diff)
data: withParsedCommentaryEntries: auto-fill archive capture dates
-rw-r--r--src/data/composite/wiki-data/withParsedCommentaryEntries.js46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/data/composite/wiki-data/withParsedCommentaryEntries.js b/src/data/composite/wiki-data/withParsedCommentaryEntries.js
index f70a3ee9..5c28d20e 100644
--- a/src/data/composite/wiki-data/withParsedCommentaryEntries.js
+++ b/src/data/composite/wiki-data/withParsedCommentaryEntries.js
@@ -142,6 +142,24 @@ export default templateCompositeFrom({
     }),
 
     {
+      dependencies: ['#entries.annotation'],
+      compute: (continuation, {
+        ['#entries.annotation']: annotation,
+      }) => continuation({
+        ['#entries.webArchiveDate']:
+          annotation
+            .map(text => text?.match(/https?:\/\/web.archive.org\/web\/([0-9]{8,8})[0-9]*\//))
+            .map(match => match?.[1])
+            .map(dateText =>
+              (dateText
+                ? dateText.slice(0, 4) + '/' +
+                  dateText.slice(4, 6) + '/' +
+                  dateText.slice(6, 8)
+                : null)),
+      }),
+    },
+
+    {
       dependencies: ['#entries.date'],
       compute: (continuation, {
         ['#entries.date']: date,
@@ -152,19 +170,35 @@ export default templateCompositeFrom({
     },
 
     {
-      dependencies: ['#entries.accessDate'],
+      dependencies: ['#entries.accessDate', '#entries.webArchiveDate'],
       compute: (continuation, {
         ['#entries.accessDate']: accessDate,
+        ['#entries.webArchiveDate']: webArchiveDate,
       }) => continuation({
         ['#entries.accessDate']:
-          accessDate.map(date => date ? new Date(date) : null),
+          stitchArrays({accessDate, webArchiveDate})
+            .map(({accessDate, webArchiveDate}) =>
+              accessDate ??
+              webArchiveDate ??
+              null)
+            .map(date => date ? new Date(date) : date),
       }),
     },
 
-    fillMissingListItems({
-      list: '#entries.accessKind',
-      fill: input.value(null),
-    }),
+    {
+      dependencies: ['#entries.accessKind', '#entries.webArchiveDate'],
+      compute: (continuation, {
+        ['#entries.accessKind']: accessKind,
+        ['#entries.webArchiveDate']: webArchiveDate,
+      }) => continuation({
+        ['#entries.accessKind']:
+          stitchArrays({accessKind, webArchiveDate})
+            .map(({accessKind, webArchiveDate}) =>
+              accessKind ??
+              (webArchiveDate && 'captured') ??
+              null),
+      }),
+    },
 
     {
       dependencies: [