« get me outta code hell

data: amorphize annotated reference lists - 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>2024-12-25 17:40:09 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-12-25 17:53:26 -0400
commitf43c4ba77f5598d5234b21fcd03fa7788b17afe5 (patch)
tree825c60368502f9fb1809b252656bfd2e24863712 /src/data/yaml.js
parentb65edcb7e61d2e0c4de6528bb8ee3e5d2032a500 (diff)
data: amorphize annotated reference lists
Diffstat (limited to 'src/data/yaml.js')
-rw-r--r--src/data/yaml.js26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index f7c36b89..0bc2e298 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -569,27 +569,31 @@ export function parseContributionPresets(list) {
   });
 }
 
-export function parseAnnotatedReferences(entries) {
+export function parseAnnotatedReferences(entries, {
+  referenceField = 'References',
+  annotationField = 'Annotation',
+  referenceProperty = 'reference',
+  annotationProperty = 'annotation',
+} = {}) {
   return parseArrayEntries(entries, item => {
-    if (typeof item === 'object' && item['References'])
+    if (typeof item === 'object' && item[referenceField])
       return {
-        reference: item['References'],
-        annotation: item['Annotation'] ?? null,
+        [referenceProperty]: item[referenceField],
+        [annotationProperty]: item[annotationField] ?? null,
       };
 
     if (typeof item !== 'string') return item;
 
     const match = item.match(extractAccentRegex);
-    if (!match) {
+    if (!match)
       return {
-        reference: item,
-        annotation: null,
-      }
-    }
+        [referenceProperty]: item,
+        [annotationProperty]: null,
+      };
 
     return {
-      reference: match.groups.main,
-      annotation: match.groups.accent,
+      [referenceProperty]: match.groups.main,
+      [annotationProperty]: match.groups.accent ?? null,
     };
   });
 }