From 596484cb663484ca41ae650ee2ece9d15f722f74 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 2 Jun 2023 10:08:33 -0300 Subject: content: rename generateAlbumNavLinks -> generateAlbumNavAccent --- src/content/dependencies/generateAlbumInfoPage.js | 6 +- src/content/dependencies/generateAlbumNavAccent.js | 120 +++++++++++++++++++++ src/content/dependencies/generateAlbumNavLinks.js | 120 --------------------- src/content/dependencies/generateTrackInfoPage.js | 6 +- 4 files changed, 126 insertions(+), 126 deletions(-) create mode 100644 src/content/dependencies/generateAlbumNavAccent.js delete mode 100644 src/content/dependencies/generateAlbumNavLinks.js (limited to 'src') diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js index 3257b139..1894ce4e 100644 --- a/src/content/dependencies/generateAlbumInfoPage.js +++ b/src/content/dependencies/generateAlbumInfoPage.js @@ -4,7 +4,7 @@ import {sortAlbumsTracksChronologically} from '../../util/wiki-data.js'; export default { contentDependencies: [ 'generateAlbumInfoPageContent', - 'generateAlbumNavLinks', + 'generateAlbumNavAccent', 'generateAlbumSidebar', 'generateAlbumSocialEmbed', 'generateAlbumStyleRules', @@ -36,7 +36,7 @@ export default { ]), }), - albumNavLinks: relation('generateAlbumNavLinks', album, null), + albumNavAccent: relation('generateAlbumNavAccent', album, null), chronologyLinks: relation('generateChronologyLinks'), content: relation('generateAlbumInfoPageContent', album), @@ -73,7 +73,7 @@ export default { { auto: 'current', accent: - relations.albumNavLinks.slots({ + relations.albumNavAccent.slots({ showTrackNavigation: true, showExtraLinks: true, }), diff --git a/src/content/dependencies/generateAlbumNavAccent.js b/src/content/dependencies/generateAlbumNavAccent.js new file mode 100644 index 00000000..9d1d87c3 --- /dev/null +++ b/src/content/dependencies/generateAlbumNavAccent.js @@ -0,0 +1,120 @@ +import {empty} from '../../util/sugar.js'; + +export default { + contentDependencies: [ + 'generatePreviousNextLinks', + 'linkTrack', + 'linkAlbumCommentary', + 'linkAlbumGallery', + ], + + extraDependencies: ['html', 'language'], + + relations(relation, album, track) { + const relations = {}; + + relations.previousNextLinks = + relation('generatePreviousNextLinks'); + + relations.previousTrackLink = null; + relations.nextTrackLink = null; + + if (track) { + const index = album.tracks.indexOf(track); + + if (index > 0) { + relations.previousTrackLink = + relation('linkTrack', album.tracks[index - 1]); + } + + if (index < album.tracks.length - 1) { + relations.nextTrackLink = + relation('linkTrack', album.tracks[index + 1]); + } + } + + if (album.tracks.some(t => t.hasUniqueCoverArt)) { + relations.albumGalleryLink = + relation('linkAlbumGallery', album); + } + + if (album.commentary || album.tracks.some(t => t.commentary)) { + relations.albumCommentaryLink = + relation('linkAlbumCommentary', album); + } + + return relations; + }, + + data(album, track) { + return { + hasMultipleTracks: album.tracks.length > 1, + isTrackPage: !!track, + }; + }, + + generate(data, relations, {html, language}) { + return html.template({ + annotation: `generateAlbumNavAccent`, + + slots: { + showTrackNavigation: {type: 'boolean', default: false}, + showExtraLinks: {type: 'boolean', default: false}, + + currentExtra: { + validate: v => v.is('gallery', 'commentary'), + }, + }, + + content(slots) { + const {content: extraLinks = []} = + slots.showExtraLinks && + {content: [ + relations.albumGalleryLink?.slots({ + attributes: {class: slots.currentExtra === 'gallery' && 'current'}, + content: language.$('albumPage.nav.gallery'), + }), + + relations.albumCommentaryLink?.slots({ + attributes: {class: slots.currentExtra === 'commentary' && 'current'}, + content: language.$('albumPage.nav.commentary'), + }), + ]}; + + const {content: previousNextLinks = []} = + slots.showTrackNavigation && + data.isTrackPage && + data.hasMultipleTracks && + relations.previousNextLinks.slots({ + previousLink: relations.previousTrackLink, + nextLink: relations.nextTrackLink, + }); + + const randomLink = + slots.showTrackNavigation && + data.hasMultipleTracks && + html.tag('a', + { + href: '#', + 'data-random': 'track-in-album', + id: 'random-button', + }, + (data.isTrackPage + ? language.$('trackPage.nav.random') + : language.$('albumPage.nav.randomTrack'))); + + const allLinks = [ + ...previousNextLinks, + ...extraLinks, + randomLink, + ].filter(Boolean); + + if (empty(allLinks)) { + return html.blank(); + } + + return `(${language.formatUnitList(allLinks)})` + }, + }); + }, +}; diff --git a/src/content/dependencies/generateAlbumNavLinks.js b/src/content/dependencies/generateAlbumNavLinks.js deleted file mode 100644 index e4eb6c54..00000000 --- a/src/content/dependencies/generateAlbumNavLinks.js +++ /dev/null @@ -1,120 +0,0 @@ -import {empty} from '../../util/sugar.js'; - -export default { - contentDependencies: [ - 'generatePreviousNextLinks', - 'linkTrack', - 'linkAlbumCommentary', - 'linkAlbumGallery', - ], - - extraDependencies: ['html', 'language'], - - relations(relation, album, track) { - const relations = {}; - - relations.previousNextLinks = - relation('generatePreviousNextLinks'); - - relations.previousTrackLink = null; - relations.nextTrackLink = null; - - if (track) { - const index = album.tracks.indexOf(track); - - if (index > 0) { - relations.previousTrackLink = - relation('linkTrack', album.tracks[index - 1]); - } - - if (index < album.tracks.length - 1) { - relations.nextTrackLink = - relation('linkTrack', album.tracks[index + 1]); - } - } - - if (album.tracks.some(t => t.hasUniqueCoverArt)) { - relations.albumGalleryLink = - relation('linkAlbumGallery', album); - } - - if (album.commentary || album.tracks.some(t => t.commentary)) { - relations.albumCommentaryLink = - relation('linkAlbumCommentary', album); - } - - return relations; - }, - - data(album, track) { - return { - hasMultipleTracks: album.tracks.length > 1, - isTrackPage: !!track, - }; - }, - - generate(data, relations, {html, language}) { - return html.template({ - annotation: `generateAlbumNavLinks`, - - slots: { - showTrackNavigation: {type: 'boolean', default: false}, - showExtraLinks: {type: 'boolean', default: false}, - - currentExtra: { - validate: v => v.is('gallery', 'commentary'), - }, - }, - - content(slots) { - const {content: extraLinks = []} = - slots.showExtraLinks && - {content: [ - relations.albumGalleryLink?.slots({ - attributes: {class: slots.currentExtra === 'gallery' && 'current'}, - content: language.$('albumPage.nav.gallery'), - }), - - relations.albumCommentaryLink?.slots({ - attributes: {class: slots.currentExtra === 'commentary' && 'current'}, - content: language.$('albumPage.nav.commentary'), - }), - ]}; - - const {content: previousNextLinks = []} = - slots.showTrackNavigation && - data.isTrackPage && - data.hasMultipleTracks && - relations.previousNextLinks.slots({ - previousLink: relations.previousTrackLink, - nextLink: relations.nextTrackLink, - }); - - const randomLink = - slots.showTrackNavigation && - data.hasMultipleTracks && - html.tag('a', - { - href: '#', - 'data-random': 'track-in-album', - id: 'random-button', - }, - (data.isTrackPage - ? language.$('trackPage.nav.random') - : language.$('albumPage.nav.randomTrack'))); - - const allLinks = [ - ...previousNextLinks, - ...extraLinks, - randomLink, - ].filter(Boolean); - - if (empty(allLinks)) { - return html.blank(); - } - - return `(${language.formatUnitList(allLinks)})` - }, - }); - }, -}; diff --git a/src/content/dependencies/generateTrackInfoPage.js b/src/content/dependencies/generateTrackInfoPage.js index 5900b27e..197d6312 100644 --- a/src/content/dependencies/generateTrackInfoPage.js +++ b/src/content/dependencies/generateTrackInfoPage.js @@ -4,7 +4,7 @@ import {sortAlbumsTracksChronologically} from '../../util/wiki-data.js'; export default { contentDependencies: [ 'generateTrackInfoPageContent', - 'generateAlbumNavLinks', + 'generateAlbumNavAccent', 'generateAlbumSidebar', 'generateAlbumStyleRules', 'generateChronologyLinks', @@ -54,7 +54,7 @@ export default { albumLink: relation('linkAlbum', track.album), trackLink: relation('linkTrack', track), - albumNavLinks: relation('generateAlbumNavLinks', track.album, track), + albumNavAccent: relation('generateAlbumNavAccent', track.album, track), chronologyLinks: relation('generateChronologyLinks'), content: relation('generateTrackInfoPageContent', track), @@ -107,7 +107,7 @@ export default { ], navBottomRowContent: - relations.albumNavLinks.slots({ + relations.albumNavAccent.slots({ showTrackNavigation: true, showExtraLinks: false, }), -- cgit 1.3.0-6-gf8a5