« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/data/composite/wiki-data/withParsedCommentaryEntries.js21
-rw-r--r--src/util/wiki-data.js12
-rw-r--r--test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js18
3 files changed, 23 insertions, 28 deletions
diff --git a/src/data/composite/wiki-data/withParsedCommentaryEntries.js b/src/data/composite/wiki-data/withParsedCommentaryEntries.js
index 9e33cdac..7b1c9484 100644
--- a/src/data/composite/wiki-data/withParsedCommentaryEntries.js
+++ b/src/data/composite/wiki-data/withParsedCommentaryEntries.js
@@ -87,7 +87,7 @@ export default templateCompositeFrom({
       prefix: input.value('#entries'),
       properties: input.value([
         'artistReference',
-        'boldfaceArtist',
+        'artistDisplayText',
         'annotation',
         'date',
       ]),
@@ -105,15 +105,10 @@ export default templateCompositeFrom({
       '#resolvedReferenceList': '#entries.artist',
     }),
 
-    {
-      dependencies: ['#entries.boldfaceArtist'],
-      compute: (continuation, {
-        ['#entries.boldfaceArtist']: boldfaceArtist,
-      }) => continuation({
-        ['#entries.boldfaceArtist']:
-          boldfaceArtist.map(boldface => boldface ? true : false),
-      }),
-    },
+    fillMissingListItems({
+      list: '#entries.artistDisplayText',
+      fill: input.value(null),
+    }),
 
     fillMissingListItems({
       list: '#entries.annotation',
@@ -133,7 +128,7 @@ export default templateCompositeFrom({
     {
       dependencies: [
         '#entries.artist',
-        '#entries.boldfaceArtist',
+        '#entries.artistDisplayText',
         '#entries.annotation',
         '#entries.date',
         '#entries.body',
@@ -141,7 +136,7 @@ export default templateCompositeFrom({
 
       compute: (continuation, {
         ['#entries.artist']: artist,
-        ['#entries.boldfaceArtist']: boldfaceArtist,
+        ['#entries.artistDisplayText']: artistDisplayText,
         ['#entries.annotation']: annotation,
         ['#entries.date']: date,
         ['#entries.body']: body,
@@ -149,7 +144,7 @@ export default templateCompositeFrom({
         ['#parsedCommentaryEntries']:
           stitchArrays({
             artist,
-            boldfaceArtist,
+            artistDisplayText,
             annotation,
             date,
             body,
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js
index 5ab01225..75a141d3 100644
--- a/src/util/wiki-data.js
+++ b/src/util/wiki-data.js
@@ -629,9 +629,10 @@ export function sortFlashesChronologically(data, {
 
 // Specific data utilities
 
-// Matches heading details from commentary data in roughly the format:
+// Matches heading details from commentary data in roughly the formats:
 //
 //    <i>artistReference:</i> (annotation, date)
+//    <i>artistReference|artistDisplayText:</i> (annotation, date)
 //
 // where capturing group "annotation" can be any text at all, except that the
 // last entry (past a comma or the only content within parentheses), if parsed
@@ -643,16 +644,15 @@ export function sortFlashesChronologically(data, {
 //   * "12/25/2019" - one or two number digits, a slash, one or two number
 //     digits, a slash, and two to four number digits
 //
-// The artist reference can optionally be boldface (in <b></b>), which will be
-// captured as non-null in "boldfaceArtist". Otherwise it is all the characters
-// between <i> and </i> and is captured in "artistReference" and is either the
-// name of an artist or an "artist:directory"-style reference.
+// Capturing group "artistReference" is all the characters between <i> and </i>
+// (apart from the pipe and "artistDisplayText" text, if present), and is either
+// the name of an artist or an "artist:directory"-style reference.
 //
 // 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.
 //
 export const commentaryRegex =
-  /^<i>(?<boldfaceArtist><b>)?(?<artistReference>.+):(?:<\/b>)?<\/i>(?: \((?<annotation>(?:.*?(?=[,)]))*?)(?:,? ?(?<date>[0-9]{1,2} [^,]*[0-9]{4,4}|[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}))?\))?/gm;
+  /^<i>(?<artistReference>.+?)(?:\|(?<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,2}\/[0-9]{1,2}\/[0-9]{2,4}))?\))?/gm;
 
 export function filterAlbumsByCommentary(albums) {
   return albums
diff --git a/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js b/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js
index 7b456449..50570de6 100644
--- a/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js
+++ b/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js
@@ -50,7 +50,7 @@ t.test(`withParsedCommentaryEntries: basic behavior`, t => {
   }), [
     {
       artist: artist1,
-      boldfaceArtist: false,
+      artistDisplayText: null,
       annotation: null,
       date: null,
       body: `Some commentary.\nVery cool.`,
@@ -60,40 +60,40 @@ t.test(`withParsedCommentaryEntries: basic behavior`, t => {
   t.match(composite.expose.compute({
     artistData,
     from:
-      `<i>Mobius Trip:</i> (music, art, 12 January 2015)\n` +
+      `<i>Mobius Trip|Moo-bius Trip:</i> (music, art, 12 January 2015)\n` +
       `First commentary entry.\n` +
       `Very cool.\n` +
-      `<i><b>Hadron Kaleido:</b></i> (moral support, 4/4/2022)\n` +
+      `<i>Hadron Kaleido|<b>[[artist:hadron-kaleido|The Ol' Hadron]]</b>:</i> (moral support, 4/4/2022)\n` +
       `Second commentary entry. Yes. So cool.\n` +
-      `<i>Mystery Artist:</i> (pingas)\n` +
+      `<i>Mystery Artist:</i> (pingas, August 25, 2023)\n` +
       `Oh no.. Oh dear...\n` +
       `<i>Mobius Trip:</i>\n` +
       `And back around we go.`,
   }), [
     {
       artist: artist1,
-      boldfaceArtist: false,
+      artistDisplayText: `Moo-bius Trip`,
       annotation: `music, art`,
       date: new Date('12 January 2015'),
       body: `First commentary entry.\nVery cool.`,
     },
     {
       artist: artist2,
-      boldfaceArtist: true,
+      artistDisplayText: `<b>[[artist:hadron-kaleido|The Ol' Hadron]]</b>`,
       annotation: `moral support`,
       date: new Date('4 April 2022'),
       body: `Second commentary entry. Yes. So cool.`,
     },
     {
       artist: null,
-      boldfaceArtist: false,
+      artistDisplayText: null,
       annotation: `pingas`,
-      date: null,
+      date: new Date('25 August 2023'),
       body: `Oh no.. Oh dear...`,
     },
     {
       artist: artist1,
-      boldfaceArtist: false,
+      artistDisplayText: null,
       annotation: null,
       date: null,
       body: `And back around we go.`,