From d5122a2657cbf1e39c674e47788cd1e16fdeaed9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 2 May 2023 13:34:45 -0300 Subject: content: generateAlbumSidebar: move group boxes into own function This will make for cleaner dependencies and finer-grained refreshing. --- .../dependencies/generateAlbumSidebarGroupBox.js | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/content/dependencies/generateAlbumSidebarGroupBox.js (limited to 'src/content/dependencies/generateAlbumSidebarGroupBox.js') diff --git a/src/content/dependencies/generateAlbumSidebarGroupBox.js b/src/content/dependencies/generateAlbumSidebarGroupBox.js new file mode 100644 index 00000000..0679e8fc --- /dev/null +++ b/src/content/dependencies/generateAlbumSidebarGroupBox.js @@ -0,0 +1,82 @@ +import {empty} from '../../util/sugar.js'; + +export default { + contentDependencies: ['linkAlbum', 'linkExternal', 'linkGroup'], + extraDependencies: ['html', 'language', 'transformMultiline'], + + relations(relation, album, group) { + const relations = {}; + + relations.groupLink = + relation('linkGroup', group); + + relations.externalLinks = + group.urls.map(url => + relation('linkExternal', url)); + + const albums = group.albums.filter(album => album.date); + const index = albums.indexOf(album); + const previousAlbum = (index > 0) && albums[index - 1]; + const nextAlbum = (index < albums.length - 1) && albums[index + 1]; + + if (previousAlbum) { + relations.previousAlbumLink = + relation('linkAlbum', previousAlbum); + } + + if (nextAlbum) { + relations.nextAlbumLink = + relation('linkAlbum', nextAlbum); + } + + return relations; + }, + + data(album, group) { + return { + description: group.descriptionShort, + }; + }, + + generate(data, relations, {html, language, transformMultiline}) { + return html.template({ + annotation: `generateAlbumSidebarGroupBox`, + + slots: { + isAlbumPage: {type: 'boolean', default: false}, + }, + + content(slots) { + return html.tags([ + html.tag('h1', + language.$('albumSidebar.groupBox.title', { + group: relations.groupLink, + })), + + slots.isAlbumPage && + transformMultiline(data.description), + + !empty(relations.externalLinks) && + html.tag('p', + language.$('releaseInfo.visitOn', { + links: language.formatDisjunctionList(relations.externalLinks), + })), + + slots.isAlbumPage && + relations.nextAlbumLink && + html.tag('p', {class: 'group-chronology-link'}, + language.$('albumSidebar.groupBox.next', { + album: relations.nextAlbumLink, + })), + + slots.isAlbumPage && + relations.previousAlbumLink && + html.tag('p', {class: 'group-chronology-link'}, + language.$('albumSidebar.groupBox.previous', { + album: relations.previousAlbumLink, + })), + ]); + }, + }); + }, +}; -- cgit 1.3.0-6-gf8a5