« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common-util/sort.js6
-rw-r--r--src/content/dependencies/linkThing.js6
-rw-r--r--src/content/dependencies/transformContent.js5
-rw-r--r--src/data/things/Track.js47
-rw-r--r--src/data/things/sorting-rule/ThingSortingRule.js9
5 files changed, 66 insertions, 7 deletions
diff --git a/src/common-util/sort.js b/src/common-util/sort.js
index b87ef500..d89fa4cc 100644
--- a/src/common-util/sort.js
+++ b/src/common-util/sort.js
@@ -40,11 +40,15 @@ export function normalizeName(s) {
   // punctuation, with a single typical space, then trim the ends.
   s = s
     .replace(
-      /[\p{Separator}\p{Dash_Punctuation}\p{Connector_Punctuation}]+/gu,
+      /[/\p{Separator}\p{Dash_Punctuation}\p{Connector_Punctuation}]+/gu,
       ' '
     )
     .trim();
 
+  // Zero-prefix sequences of digits (bounded by only select characters),
+  // so lesser-value numbers precede greater.
+  s = s.replace(/(?<=[ ({\[<]|^)\d+(?=[ )}\]>]|$)/g, match => match.padStart(5, '0'));
+
   // Discard anything that isn't a letter, number, space, or apostrophe.
   s = s.replace(/[^\p{Letter}\p{Number} ']/gu, '').trim();
 
diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js
index 64b3ddcd..100b3e89 100644
--- a/src/content/dependencies/linkThing.js
+++ b/src/content/dependencies/linkThing.js
@@ -19,9 +19,13 @@ export default {
   data: (pathKey, thing) => ({
     name: thing.name,
     nameShort: thing.nameShort ?? thing.shortName,
-    nameDetail: thing.nameDetail,
     nameText: thing.nameText,
 
+    nameDetail:
+      thing.nameDetail ??
+      thing.nameDetailAcrossWiki ??
+      null,
+
     path:
       (pathKey
         ? [pathKey, thing.directory]
diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js
index 4079f0f0..243ab502 100644
--- a/src/content/dependencies/transformContent.js
+++ b/src/content/dependencies/transformContent.js
@@ -635,6 +635,11 @@ export default {
               link.setSlot('tooltipStyle', 'none');
             }
 
+            // TODO: The same, the same.
+            if (!errors(() => link.getSlotDescription('showNameDetail'))) {
+              link.setSlot('showNameDetail', 'inside');
+            }
+
             let doTheAbsorbyThing = false;
 
             // TODO: This is just silly.
diff --git a/src/data/things/Track.js b/src/data/things/Track.js
index 7ce55e51..7eff2000 100644
--- a/src/data/things/Track.js
+++ b/src/data/things/Track.js
@@ -677,6 +677,10 @@ export class Track extends Thing {
             : continuation()),
       },
 
+      exposeDependency('nameForSorting'),
+    ],
+
+    nameForSorting: [
       {
         dependencies: ['name', 'nameDetailAcrossWiki'],
         compute: (continuation, {name, nameDetailAcrossWiki}) =>
@@ -1453,30 +1457,65 @@ export class Track extends Thing {
     return this.album.getAlbumArtPath(filename);
   }
 
-  countOwnContributionInContributionTotals(_contrib) {
+  countOwnContributionInContributionTotals(contrib) {
     if (!this.countInArtistTotals) {
       return false;
     }
 
     if (this.isSecondaryRelease) {
-      return false;
+      const correspondingContrib =
+        this.getCorrespondingMainReleaseContrib(contrib);
+
+      if (correspondingContrib) {
+        return false;
+      }
     }
 
     return true;
   }
 
-  countOwnContributionInDurationTotals(_contrib) {
+  countOwnContributionInDurationTotals(contrib) {
     if (!this.countInArtistTotals) {
       return false;
     }
 
     if (this.isSecondaryRelease) {
-      return false;
+      const correspondingContrib =
+        this.getCorrespondingMainReleaseContrib(contrib);
+
+      if (correspondingContrib) {
+        return false;
+      }
     }
 
     return true;
   }
 
+  getCorrespondingMainReleaseContrib(contrib) {
+    if (!this.isSecondaryRelease) return null;
+
+    const filterMatchingContrib = c =>
+      c.artist === contrib.artist &&
+      c.annotation === contrib.annotation;
+
+    const myList =
+      this[contrib.thingProperty]
+        .filter(filterMatchingContrib);
+
+    const mainList =
+      this.mainReleaseTrack[contrib.thingProperty]
+        .filter(filterMatchingContrib);
+
+    const index = myList.indexOf(contrib);
+
+    if (index === -1) {
+      const key = contrib.thingProperty;
+      throw new Error(`Couldn't find contribution in track's own ${key}`);
+    }
+
+    return mainList.at(index) ?? null;
+  }
+
   [inspect.custom](depth) {
     const parts = [];
 
diff --git a/src/data/things/sorting-rule/ThingSortingRule.js b/src/data/things/sorting-rule/ThingSortingRule.js
index b5cc76dc..6dbaccf7 100644
--- a/src/data/things/sorting-rule/ThingSortingRule.js
+++ b/src/data/things/sorting-rule/ThingSortingRule.js
@@ -51,7 +51,14 @@ export class ThingSortingRule extends SortingRule {
           continue;
         }
 
-        if (lc.endsWith('name')) {
+        if (lc === 'name') {
+          sortByName(sortable, {
+            getName: thing =>
+              thing.nameForSorting ??
+              thing.name,
+          });
+          continue;
+        } else if (lc.endsWith('name')) {
           sortByName(sortable, {getName: get});
           continue;
         }