From cb140119b46d2f35d364461379b3ea9130d8a063 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 20 Jun 2024 16:08:20 -0300 Subject: content: generateArtistCredit --- src/content/dependencies/generateArtistCredit.js | 82 ++++++++++++++++++++++ .../generateArtistCreditWikiEditsPart.js | 55 +++++++++++++++ .../generateReleaseInfoContributionsLine.js | 74 ++++--------------- ...ateReleaseInfoContributionsLineWikiEditsPart.js | 51 -------------- 4 files changed, 151 insertions(+), 111 deletions(-) create mode 100644 src/content/dependencies/generateArtistCredit.js create mode 100644 src/content/dependencies/generateArtistCreditWikiEditsPart.js delete mode 100644 src/content/dependencies/generateReleaseInfoContributionsLineWikiEditsPart.js (limited to 'src/content') 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/generateArtistCreditWikiEditsPart.js b/src/content/dependencies/generateArtistCreditWikiEditsPart.js new file mode 100644 index 00000000..70296e39 --- /dev/null +++ b/src/content/dependencies/generateArtistCreditWikiEditsPart.js @@ -0,0 +1,55 @@ +export default { + contentDependencies: [ + 'generateTextWithTooltip', + 'generateTooltip', + 'linkContribution', + ], + + extraDependencies: ['html', 'language'], + + relations: (relation, contributions) => ({ + textWithTooltip: + relation('generateTextWithTooltip'), + + tooltip: + relation('generateTooltip'), + + contributionLinks: + contributions + .map(contrib => relation('linkContribution', contrib)), + }), + + slots: { + showAnnotation: {type: 'boolean', default: true}, + }, + + generate: (relations, slots, {language}) => + language.encapsulate('misc.artistLink.withEditsForWiki', capsule => + relations.textWithTooltip.slots({ + attributes: + {class: 'wiki-edits'}, + + text: + language.$(capsule, 'edits'), + + tooltip: + relations.tooltip.slots({ + attributes: + {class: 'wiki-edits-tooltip'}, + + content: + language.$(capsule, 'editsLine', { + [language.onlyIfOptions]: ['artists'], + + artists: + language.formatConjunctionList( + relations.contributionLinks.map(link => + link.slots({ + 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, + }), }; diff --git a/src/content/dependencies/generateReleaseInfoContributionsLineWikiEditsPart.js b/src/content/dependencies/generateReleaseInfoContributionsLineWikiEditsPart.js deleted file mode 100644 index a2a103b6..00000000 --- a/src/content/dependencies/generateReleaseInfoContributionsLineWikiEditsPart.js +++ /dev/null @@ -1,51 +0,0 @@ -export default { - contentDependencies: [ - 'generateTextWithTooltip', - 'generateTooltip', - 'linkContribution', - ], - - extraDependencies: ['language'], - - relations: (relation, contributions) => ({ - textWithTooltip: - relation('generateTextWithTooltip'), - - tooltip: - relation('generateTooltip'), - - contributionLinks: - contributions - .map(contrib => relation('linkContribution', contrib)), - }), - - generate: (relations, {language}) => - language.encapsulate('misc.artistLink.withEditsForWiki', capsule => - relations.textWithTooltip.slots({ - attributes: - {class: 'wiki-edits'}, - - text: - language.$(capsule, 'edits'), - - tooltip: - relations.tooltip.slots({ - attributes: - {class: 'wiki-edits-tooltip'}, - - content: - language.$(capsule, 'editsLine', { - [language.onlyIfOptions]: ['artists'], - - artists: - language.formatConjunctionList( - relations.contributionLinks.map(link => - link.slots({ - showAnnotation: true, - trimAnnotation: true, - preventTooltip: true, - }))), - }), - }), - })), -}; -- cgit 1.3.0-6-gf8a5