diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-06-20 16:08:20 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-08-17 15:53:45 -0300 |
commit | cb140119b46d2f35d364461379b3ea9130d8a063 (patch) | |
tree | 2c087f4f19872a81118856ba6f7729cd6041f971 /src/content/dependencies/generateArtistCredit.js | |
parent | bbfecd71976859e591d3ebef62853f4c0481484f (diff) |
content: generateArtistCredit
Diffstat (limited to 'src/content/dependencies/generateArtistCredit.js')
-rw-r--r-- | src/content/dependencies/generateArtistCredit.js | 82 |
1 files changed, 82 insertions, 0 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), + }); + }, +}; |