« get me outta code hell

data: factor out date matching in commentary heading - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/wiki-data.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-21 19:07:10 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-23 22:14:59 -0300
commit97187260c19a2e6e6b096931343e8c0ae3c2ff07 (patch)
tree891f741a0952efdfc10e5138e3a64105ab412d0c /src/util/wiki-data.js
parente12ef6d82d4a05662afd57642e51917072295cc8 (diff)
data: factor out date matching in commentary heading
Diffstat (limited to 'src/util/wiki-data.js')
-rw-r--r--src/util/wiki-data.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js
index 8c318d02..aa7f1f56 100644
--- a/src/util/wiki-data.js
+++ b/src/util/wiki-data.js
@@ -89,8 +89,12 @@ export function getKebabCase(name) {
 // This regular expression *doesn't* match bodies, which will need to be parsed
 // out of the original string based on the indices matched using this.
 //
+
+const dateRegex = groupName =>
+  String.raw`(?<${groupName}>[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}|[0-9]{1,2} [^,]*[0-9]{4,4}|[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4})`;
+
 const commentaryRegexRaw =
-  String.raw`^<i>(?<artistReferences>.+?)(?:\|(?<artistDisplayText>.+))?:<\/i>(?: \((?<annotation>(?:.*?(?=,|\)[^)]*$))*?)(?:,? ?(?<date>[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}|[0-9]{1,2} [^,]*[0-9]{4,4}|[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4}))?(?: (?<accessKind>captured|accessed) (?<accessDate>[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}|[0-9]{1,2} [^,]*[0-9]{4,4}|[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4}))?\))?`;
+  String.raw`^<i>(?<artistReferences>.+?)(?:\|(?<artistDisplayText>.+))?:<\/i>(?: \((?<annotation>(?:.*?(?=,|\)[^)]*$))*?)(?:,? ?${dateRegex('date')})?(?: (?<accessKind>captured|accessed) ${dateRegex('accessDate')})?\))?`;
 export const commentaryRegexCaseInsensitive =
   new RegExp(commentaryRegexRaw, 'gmi');
 export const commentaryRegexCaseSensitive =