« get me outta code hell

data, content: Contribution.artistText - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/yaml.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-01-26 19:52:39 -0400
committer(quasar) nebula <qznebula@protonmail.com>2026-01-26 19:52:39 -0400
commitdc0d479d6698bf1db3f5181f48332da26ebd47f7 (patch)
tree56822ab59d08474e1d6184a3b19aafcea4323a4d /src/data/yaml.js
parenta8f36db5eac0a6ba89127ef393a68ffe94cf79a0 (diff)
data, content: Contribution.artistText preview
Diffstat (limited to 'src/data/yaml.js')
-rw-r--r--src/data/yaml.js30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 50496c00..2afaffb5 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -646,6 +646,9 @@ export const extractAccentRegex =
 export const extractPrefixAccentRegex =
   /^(?:\((?<accent>.*)\) )?(?<main>.*?)$/;
 
+export const asNameRegex =
+  /^as (?<name>\S.+?)(?:(?<=\S)[,:] | +- |$)(?: *(?<annotation>.*))?$/;
+
 // TODO: Should this fit better within actual YAML loading infrastructure??
 export function parseArrayEntries(entries, mapFn) {
   // If this isn't something we can parse, just return it as-is.
@@ -679,12 +682,14 @@ export function parseContributors(entries) {
     if (typeof item === 'object' && item['Who'])
       return {
         artist: item['Who'],
+        artistText: item['As'] ?? null,
         annotation: item['What'] ?? null,
       };
 
     if (typeof item === 'object' && item['Artist'])
       return {
         artist: item['Artist'],
+        artistText: item['Artist Text'] ?? null,
         annotation: item['Annotation'] ?? null,
 
         countInContributionTotals: item['Count In Contribution Totals'] ?? null,
@@ -693,13 +698,28 @@ export function parseContributors(entries) {
 
     if (typeof item !== 'string') return item;
 
-    const match = item.match(extractAccentRegex);
+    let match;
+
+    match = item.match(extractAccentRegex);
     if (!match) return item;
 
-    return {
-      artist: match.groups.main,
-      annotation: match.groups.accent ?? null,
-    };
+    const {accent} = match.groups;
+
+    let artist = match.groups.main;
+    let artistText = null;
+    let annotation = null;
+
+    if (accent) {
+      match = accent.match(asNameRegex);
+      if (match) {
+        artistText = match.groups.name;
+        annotation = match.groups.annotation ?? null;
+      } else {
+        annotation = accent;
+      }
+    }
+
+    return {artist, artistText, annotation};
   });
 }