From 5a68a93b5264f9058a94e3ecb16366d596e1a153 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 21 Jun 2024 10:45:23 -0300 Subject: data: withParsedCommentaryEntries: auto-fill archive capture dates --- .../wiki-data/withParsedCommentaryEntries.js | 46 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'src/data/composite/wiki-data') 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 @@ -141,6 +141,24 @@ export default templateCompositeFrom({ fill: input.value(null), }), + { + 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, { @@ -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: [ -- cgit 1.3.0-6-gf8a5