diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-13 15:11:03 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-13 21:19:05 -0400 |
commit | eb8670ee11fd0a68c02ef96227b4475f08157ace (patch) | |
tree | f21225d00abe35f560b228116d95fc18156d6636 /src/content/dependencies | |
parent | 652ef50bfda628e245f7dd5021f0366f4ec55c5e (diff) |
content: generateCoverArtwork: avoid duplicate short names
Diffstat (limited to 'src/content/dependencies')
-rw-r--r-- | src/content/dependencies/generateCoverArtwork.js | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/src/content/dependencies/generateCoverArtwork.js b/src/content/dependencies/generateCoverArtwork.js index 7f720093..d0941d2e 100644 --- a/src/content/dependencies/generateCoverArtwork.js +++ b/src/content/dependencies/generateCoverArtwork.js @@ -1,25 +1,45 @@ -import {empty} from '#sugar'; +import {empty, stitchArrays} from '#sugar'; export default { contentDependencies: ['image', 'linkArtTag'], extraDependencies: ['html'], - relations(relation, artTags) { - const relations = {}; + query: (artTags) => ({ + linkableArtTags: + (artTags + ? artTags.filter(tag => !tag.isContentWarning) + : []), + }), - relations.image = - relation('image', artTags); + relations: (relation, query, artTags) => ({ + image: + relation('image', artTags), - if (artTags) { - relations.tagLinks = - artTags - .filter(tag => !tag.isContentWarning) - .map(tag => relation('linkArtTag', tag)); - } else { - relations.tagLinks = null; + tagLinks: + query.linkableArtTags + .filter(tag => !tag.isContentWarning) + .map(tag => relation('linkArtTag', tag)), + }), + + data: (query) => { + const data = {}; + + const seenShortNames = new Set(); + const duplicateShortNames = new Set(); + + for (const {nameShort: shortName} of query.linkableArtTags) { + if (seenShortNames.has(shortName)) { + duplicateShortNames.add(shortName); + } else { + seenShortNames.add(shortName); + } } - return relations; + data.preferShortName = + query.linkableArtTags + .map(artTag => !duplicateShortNames.has(artTag.nameShort)); + + return data; }, slots: { @@ -41,7 +61,7 @@ export default { }, }, - generate(relations, slots, {html}) { + generate(data, relations, slots, {html}) { switch (slots.mode) { case 'primary': return html.tags([ @@ -57,10 +77,12 @@ export default { !empty(relations.tagLinks) && html.tag('ul', {class: 'image-details'}, - relations.tagLinks - .map(tagLink => + stitchArrays({ + tagLink: relations.tagLinks, + preferShortName: data.preferShortName, + }).map(({tagLink, preferShortName}) => html.tag('li', - tagLink.slot('preferShortName', true)))), + tagLink.slot('preferShortName', preferShortName)))), ]); case 'thumbnail': |