« 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/content/dependencies/generateArtistCredit.js82
-rw-r--r--src/content/dependencies/generateArtistCreditWikiEditsPart.js (renamed from src/content/dependencies/generateReleaseInfoContributionsLineWikiEditsPart.js)10
-rw-r--r--src/content/dependencies/generateReleaseInfoContributionsLine.js74
3 files changed, 103 insertions, 63 deletions
diff --git a/src/content/dependencies/generateArtistCredit.js b/src/content/dependencies/generateArtistCredit.js
new file mode 100644
index 00000000..51a3bb48
--- /dev/null
+++ b/src/content/dependencies/generateArtistCredit.js
@@ -0,0 +1,82 @@
+import {empty} from '#sugar';
+
+export default {
+  contentDependencies: [
+    'generateArtistCreditWikiEditsPart',
+    'linkContribution',
+  ],
+
+  extraDependencies: ['html', 'language'],
+
+  query: (contributions) => ({
+    normalContributions:
+      contributions
+        .filter(contrib => !contrib.annotation?.startsWith(`edits for wiki`)),
+
+    wikiEditContributions:
+      contributions
+        .filter(contrib => contrib.annotation?.startsWith(`edits for wiki`)),
+  }),
+
+  relations: (relation, query, _contributions) => ({
+    contributionLinks:
+      query.normalContributions
+        .map(contrib => relation('linkContribution', contrib)),
+
+    wikiEditsPart:
+      relation('generateArtistCreditWikiEditsPart',
+        query.wikiEditContributions),
+  }),
+
+  data: (query, _contributions) => ({
+    hasWikiEdits:
+      !empty(query.wikiEditContributions),
+  }),
+
+  slots: {
+    showAnnotation: {type: 'boolean', default: true},
+    showExternalLinks: {type: 'boolean', default: true},
+    showChronology: {type: 'boolean', default: true},
+
+    trimAnnotation: {type: 'boolean', default: false},
+
+    chronologyKind: {type: 'string'},
+
+    stringKey: {type: 'string'},
+  },
+
+  generate(data, relations, slots, {language}) {
+    const contributionsList =
+      language.formatConjunctionList(
+        relations.contributionLinks.map(link =>
+          link.slots({
+            showAnnotation: slots.showAnnotation,
+            showExternalLinks: slots.showExternalLinks,
+            showChronology: slots.showChronology,
+
+            trimAnnotation: slots.trimAnnotation,
+
+            chronologyKind: slots.chronologyKind,
+          })));
+
+    return language.$(slots.stringKey, {
+      [language.onlyIfOptions]: ['artists'],
+
+      artists:
+        (data.hasWikiEdits
+          ? language.encapsulate('misc.artistLink.withEditsForWiki', capsule =>
+              language.$(capsule, {
+                // It's nonsense to display "+ edits" without
+                // having any regular contributions, also.
+                [language.onlyIfOptions]: ['artists'],
+
+                artists: contributionsList,
+                edits:
+                  relations.wikiEditsPart.slots({
+                    showAnnotation: slots.showAnnotation,
+                  }),
+              }))
+          : contributionsList),
+    });
+  },
+};
diff --git a/src/content/dependencies/generateReleaseInfoContributionsLineWikiEditsPart.js b/src/content/dependencies/generateArtistCreditWikiEditsPart.js
index a2a103b6..70296e39 100644
--- a/src/content/dependencies/generateReleaseInfoContributionsLineWikiEditsPart.js
+++ b/src/content/dependencies/generateArtistCreditWikiEditsPart.js
@@ -5,7 +5,7 @@ export default {
     'linkContribution',
   ],
 
-  extraDependencies: ['language'],
+  extraDependencies: ['html', 'language'],
 
   relations: (relation, contributions) => ({
     textWithTooltip:
@@ -19,7 +19,11 @@ export default {
         .map(contrib => relation('linkContribution', contrib)),
   }),
 
-  generate: (relations, {language}) =>
+  slots: {
+    showAnnotation: {type: 'boolean', default: true},
+  },
+
+  generate: (relations, slots, {language}) =>
     language.encapsulate('misc.artistLink.withEditsForWiki', capsule =>
       relations.textWithTooltip.slots({
         attributes:
@@ -41,7 +45,7 @@ export default {
                   language.formatConjunctionList(
                     relations.contributionLinks.map(link =>
                       link.slots({
-                        showAnnotation: true,
+                        showAnnotation: slots.showAnnotation,
                         trimAnnotation: true,
                         preventTooltip: true,
                       }))),
diff --git a/src/content/dependencies/generateReleaseInfoContributionsLine.js b/src/content/dependencies/generateReleaseInfoContributionsLine.js
index c2eb6a46..30048a78 100644
--- a/src/content/dependencies/generateReleaseInfoContributionsLine.js
+++ b/src/content/dependencies/generateReleaseInfoContributionsLine.js
@@ -1,73 +1,27 @@
-import {empty} from '#sugar';
-
 export default {
-  contentDependencies: [
-    'generateReleaseInfoContributionsLineWikiEditsPart',
-    'linkContribution',
-  ],
-
-  extraDependencies: ['html', 'language'],
-
-  query: (contributions) => ({
-    normalContributions:
-      contributions
-        .filter(contrib => !contrib.annotation?.startsWith(`edits for wiki`)),
-
-    wikiEditContributions:
-      contributions
-        .filter(contrib => contrib.annotation?.startsWith(`edits for wiki`)),
-  }),
+  contentDependencies: ['generateArtistCredit'],
+  extraDependencies: ['html'],
 
-  relations: (relation, query, _contributions) => ({
-    contributionLinks:
-      query.normalContributions
-        .map(contrib => relation('linkContribution', contrib)),
-
-    wikiEditsPart:
-      relation('generateReleaseInfoContributionsLineWikiEditsPart',
-        query.wikiEditContributions),
-  }),
-
-  data: (query, _contributions) => ({
-    hasWikiEdits:
-      !empty(query.wikiEditContributions),
+  relations: (relation, contributions) => ({
+    credit:
+      relation('generateArtistCredit', contributions),
   }),
 
   slots: {
-    showAnnotation: {type: 'boolean', default: true},
-    showExternalLinks: {type: 'boolean', default: true},
-    showChronology: {type: 'boolean', default: true},
-
     stringKey: {type: 'string'},
     chronologyKind: {type: 'string'},
   },
 
-  generate(data, relations, slots, {language}) {
-    const contributionsList =
-      language.formatConjunctionList(
-        relations.contributionLinks.map(link =>
-          link.slots({
-            showAnnotation: slots.showAnnotation,
-            showExternalLinks: slots.showExternalLinks,
-            showChronology: slots.showChronology,
-            chronologyKind: slots.chronologyKind,
-          })));
+  generate: (relations, slots) =>
+    relations.credit.slots({
+      showAnnotation: true,
+      showExternalLinks: true,
+      showChronology: true,
 
-    return language.$(slots.stringKey, {
-      [language.onlyIfOptions]: ['artists'],
+      trimAnnotation: false,
 
-      artists:
-        (data.hasWikiEdits
-          ? language.encapsulate('misc.artistLink.withEditsForWiki', capsule =>
-              language.$(capsule, {
-                // It's nonsense to display "+ edits" without
-                // having any regular contributions, also.
-                [language.onlyIfOptions]: ['artists'],
+      stringKey: slots.stringKey,
 
-                artists: contributionsList,
-                edits: relations.wikiEditsPart,
-              }))
-          : contributionsList),
-    });
-  },
+      chronologyKind: slots.chronologyKind,
+    }),
 };