diff options
Diffstat (limited to 'src/content/dependencies')
6 files changed, 231 insertions, 95 deletions
diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js index 8ba53530..8e703e2f 100644 --- a/src/content/dependencies/generateAlbumInfoPage.js +++ b/src/content/dependencies/generateAlbumInfoPage.js @@ -277,7 +277,7 @@ export default { ...relations.sidebar, - // socialEmbed: relations.socialEmbed, + socialEmbed: relations.socialEmbed, }); }, }; diff --git a/src/content/dependencies/generateAlbumSocialEmbed.js b/src/content/dependencies/generateAlbumSocialEmbed.js index 079899d3..d8f7e9c0 100644 --- a/src/content/dependencies/generateAlbumSocialEmbed.js +++ b/src/content/dependencies/generateAlbumSocialEmbed.js @@ -2,18 +2,20 @@ import {empty} from '../../util/sugar.js'; export default { contentDependencies: [ + 'generateSocialEmbed', 'generateAlbumSocialEmbedDescription', ], extraDependencies: ['absoluteTo', 'language', 'urls'], relations(relation, album) { - const relations = {}; + return { + socialEmbed: + relation('generateSocialEmbed'), - relations.description = - relation('generateAlbumSocialEmbedDescription', album); - - return relations; + description: + relation('generateAlbumSocialEmbedDescription', album), + }; }, data(album) { @@ -35,43 +37,38 @@ export default { } data.albumName = album.name; - data.albumColor = album.color; return data; }, generate(data, relations, {absoluteTo, language, urls}) { - const socialEmbed = {}; - - if (data.hasHeading) { - socialEmbed.heading = - language.$('albumPage.socialEmbed.heading', { - group: data.headingGroupName, - }); - - socialEmbed.headingLink = - absoluteTo('localized.album', data.headingGroupDirectory); - } else { - socialEmbed.heading = ''; - socialEmbed.headingLink = null; - } - - socialEmbed.title = - language.$('albumPage.socialEmbed.title', { - album: data.albumName, - }); - - socialEmbed.description = relations.description; - - if (data.hasImage) { - const imagePath = urls - .from('shared.root') - .to('media.albumCover', data.coverArtDirectory, data.coverArtFileExtension); - socialEmbed.image = '/' + imagePath; - } - - socialEmbed.color = data.albumColor; - - return socialEmbed; + return relations.socialEmbed.slots({ + title: + language.$('albumPage.socialEmbed.title', { + album: data.albumName, + }), + + description: relations.description, + + headingContent: + (data.hasHeading + ? language.$('albumPage.socialEmbed.heading', { + group: data.headingGroupName, + }) + : null), + + headingLink: + (data.hasHeading + ? absoluteTo('localized.groupGallery', data.headingGroupDirectory) + : null), + + imagePath: + (data.hasImage + ? '/' + + urls + .from('shared.root') + .to('media.albumCover', data.coverArtDirectory, data.coverArtFileExtension) + : null), + }); }, }; diff --git a/src/content/dependencies/generateSocialEmbed.js b/src/content/dependencies/generateSocialEmbed.js new file mode 100644 index 00000000..0144c7fb --- /dev/null +++ b/src/content/dependencies/generateSocialEmbed.js @@ -0,0 +1,65 @@ +export default { + extraDependencies: ['html', 'language', 'wikiData'], + + sprawl({wikiInfo}) { + return { + canonicalBase: wikiInfo.canonicalBase, + shortWikiName: wikiInfo.nameShort, + }; + }, + + data(sprawl) { + return { + canonicalBase: sprawl.canonicalBase, + shortWikiName: sprawl.shortWikiName, + }; + }, + + slots: { + mode: {validate: v => v.is('html', 'json')}, + + title: {type: 'string'}, + description: {type: 'string'}, + + headingContent: {type: 'string'}, + headingLink: {type: 'string'}, + imagePath: {type: 'string'}, + }, + + generate(data, slots, {html, language}) { + switch (slots.mode) { + case 'html': + return html.tags([ + slots.title && + html.tag('meta', {property: 'og:title', content: slots.title}), + + slots.description && + html.tag('meta', { + property: 'og:description', + content: slots.description, + }), + + slots.imagePath && + html.tag('meta', {property: 'og:image', content: slots.imagePath}), + ]); + + case 'json': + return JSON.stringify({ + author_name: + (slots.headingContent + ? language.$('misc.socialEmbed.heading', { + wikiName: data.shortWikiName, + heading: slots.headingContent, + }) + : undefined), + + author_url: + (slots.headingLink && data.canonicalBase + ? data.canonicalBase.replace(/\/$/, '') + + '/' + + slots.headingLink.replace(/^\//, '') + : undefined), + }); + } + }, +}; diff --git a/src/content/dependencies/generateTrackInfoPage.js b/src/content/dependencies/generateTrackInfoPage.js index b5ecb3b9..4487bca4 100644 --- a/src/content/dependencies/generateTrackInfoPage.js +++ b/src/content/dependencies/generateTrackInfoPage.js @@ -21,6 +21,7 @@ export default { 'generateTrackList', 'generateTrackListDividedByGroups', 'generateTrackReleaseInfo', + 'generateTrackSocialEmbed', 'linkAlbum', 'linkArtist', 'linkContribution', @@ -49,6 +50,9 @@ export default { relations.albumStyleRules = relation('generateAlbumStyleRules', track.album); + relations.socialEmbed = + relation('generateTrackSocialEmbed', track); + relations.artistChronologyContributions = getChronologyRelations(track, { contributions: [...track.artistContribs, ...track.contributorContribs], @@ -549,6 +553,8 @@ export default { }), ...relations.sidebar, + + socialEmbed: relations.socialEmbed, }); }, }; @@ -587,45 +593,9 @@ export default { }), }; - const getSocialEmbedDescription = ({ - getArtistString: _getArtistString, - language, - }) => { - const hasArtists = !empty(track.artistContribs); - const hasCoverArtists = !empty(track.coverArtistContribs); - const getArtistString = (contribs) => - _getArtistString(contribs, { - // We don't want to put actual HTML tags in social embeds (sadly - // they don't get parsed and displayed, generally speaking), so - // override the link argument so that artist "links" just show - // their names. - link: {artist: (artist) => artist.name}, - }); - if (!hasArtists && !hasCoverArtists) return ''; - return language.formatString( - 'trackPage.socialEmbed.body' + - [hasArtists && '.withArtists', hasCoverArtists && '.withCoverArtists'] - .filter(Boolean) - .join(''), - Object.fromEntries( - [ - hasArtists && ['artists', getArtistString(track.artistContribs)], - hasCoverArtists && [ - 'coverArtists', - getArtistString(track.coverArtistContribs), - ], - ].filter(Boolean) - ) - ); - }; - const page = { page: () => { return { - title: language.$('trackPage.title', {track: track.name}), - stylesheet: getAlbumStylesheet(album, {to}), - - themeColor: track.color, theme: getThemeString(track.color, { additionalVariables: [ @@ -633,26 +603,6 @@ export default { `--track-directory: ${track.directory}`, ] }), - - socialEmbed: { - heading: language.$('trackPage.socialEmbed.heading', { - album: track.album.name, - }), - headingLink: absoluteTo('localized.album', album.directory), - title: language.$('trackPage.socialEmbed.title', { - track: track.name, - }), - description: getSocialEmbedDescription({getArtistString, language}), - image: '/' + getTrackCover(track, {to: urls.from('shared.root').to}), - color: track.color, - }, - - secondaryNav: generateAlbumSecondaryNav(album, track, { - getLinkThemeString, - html, - language, - link, - }), }; }, }; diff --git a/src/content/dependencies/generateTrackSocialEmbed.js b/src/content/dependencies/generateTrackSocialEmbed.js new file mode 100644 index 00000000..0337fc46 --- /dev/null +++ b/src/content/dependencies/generateTrackSocialEmbed.js @@ -0,0 +1,86 @@ +export default { + contentDependencies: [ + 'generateSocialEmbed', + 'generateTrackSocialEmbedDescription', + ], + + extraDependencies: ['absoluteTo', 'language', 'urls'], + + relations(relation, track) { + return { + socialEmbed: + relation('generateSocialEmbed'), + + description: + relation('generateTrackSocialEmbedDescription', track), + }; + }, + + data(track) { + const {album} = track; + const data = {}; + + data.trackName = track.name; + data.albumName = album.name; + + data.trackDirectory = track.directory; + data.albumDirectory = album.directory; + + if (track.hasUniqueCoverArt) { + data.imageSource = 'track'; + data.coverArtFileExtension = track.coverArtFileExtension; + } else if (album.hasCoverArt) { + data.imageSource = 'album'; + data.coverArtFileExtension = album.coverArtFileExtension; + } else { + data.imageSource = 'none'; + } + + return data; + }, + + generate(data, relations, {absoluteTo, language, urls}) { + return relations.socialEmbed.slots({ + title: + language.$('trackPage.socialEmbed.title', { + track: data.trackName, + }), + + headingContent: + language.$('trackPage.socialEmbed.heading', { + album: data.albumName, + }), + + headingLink: + absoluteTo('localized.album', data.albumDirectory), + + imagePath: + (data.imageSource === 'album' + ? '/' + + urls + .from('shared.root') + .to('media.albumCover', data.albumDirectory, data.coverArtFileExtension) + : data.imageSource === 'track' + ? '/' + + urls + .from('shared.root') + .to('media.trackCover', data.albumDirectory, data.trackDirectory, data.coverArtFileExtension) + : null), + }); + }, +}; + +/* + socialEmbed: { + heading: language.$('trackPage.socialEmbed.heading', { + album: track.album.name, + }), + headingLink: absoluteTo('localized.album', album.directory), + title: language.$('trackPage.socialEmbed.title', { + track: track.name, + }), + description: getSocialEmbedDescription({getArtistString, language}), + image: '/' + getTrackCover(track, {to: urls.from('shared.root').to}), + color: track.color, + }, +*/ diff --git a/src/content/dependencies/generateTrackSocialEmbedDescription.js b/src/content/dependencies/generateTrackSocialEmbedDescription.js new file mode 100644 index 00000000..cf21eadf --- /dev/null +++ b/src/content/dependencies/generateTrackSocialEmbedDescription.js @@ -0,0 +1,38 @@ +export default { + generate() { + }, +}; + +/* + const getSocialEmbedDescription = ({ + getArtistString: _getArtistString, + language, + }) => { + const hasArtists = !empty(track.artistContribs); + const hasCoverArtists = !empty(track.coverArtistContribs); + const getArtistString = (contribs) => + _getArtistString(contribs, { + // We don't want to put actual HTML tags in social embeds (sadly + // they don't get parsed and displayed, generally speaking), so + // override the link argument so that artist "links" just show + // their names. + link: {artist: (artist) => artist.name}, + }); + if (!hasArtists && !hasCoverArtists) return ''; + return language.formatString( + 'trackPage.socialEmbed.body' + + [hasArtists && '.withArtists', hasCoverArtists && '.withCoverArtists'] + .filter(Boolean) + .join(''), + Object.fromEntries( + [ + hasArtists && ['artists', getArtistString(track.artistContribs)], + hasCoverArtists && [ + 'coverArtists', + getArtistString(track.coverArtistContribs), + ], + ].filter(Boolean) + ) + ); + }; +*/ |