From 589273c5e1d63e5f68ecedd68c9d4b49c36b25f4 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 12 May 2022 21:55:03 -0300 Subject: additional files These are basically supported for tracks but I've only implemented them for albums for the moment (read: I'm lazy!). --- src/misc-templates.js | 34 ++++++++++++++++++++++++++++++++++ src/page/album.js | 21 +++++++++++++++------ src/strings-default.json | 6 ++++++ src/upd8.js | 10 ++++++++++ src/url-spec.js | 1 + src/util/link.js | 13 +++++++++++++ 6 files changed, 79 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/misc-templates.js b/src/misc-templates.js index 5aec92ee..ec583989 100644 --- a/src/misc-templates.js +++ b/src/misc-templates.js @@ -28,6 +28,40 @@ const MASTODON_DOMAINS = [ 'types.pl', ]; +// "Additional Files" listing + +export function generateAdditionalFilesShortcut(additionalFiles, {language}) { + if (!additionalFiles?.length) return ''; + + return language.$('releaseInfo.additionalFiles.shortcut', { + anchorLink: `${language.$('releaseInfo.additionalFiles.shortcut.anchorLink')}`, + titles: language.formatUnitList(additionalFiles.map(g => g.title)) + }); +} + +export function generateAdditionalFilesList(additionalFiles, {language, linkFile}) { + if (!additionalFiles?.length) return ''; + + const fileCount = additionalFiles.flatMap(g => g.files).length; + + return fixWS` +

${language.$('releaseInfo.additionalFiles.heading', {fileCount})}

+
+ ${additionalFiles.map(({ title, description, files }) => fixWS` +
${(description + ? language.$('releaseInfo.additionalFiles.entry.withDescription', {title, description}) + : language.$('releaseInfo.additionalFiles.entry', {title}))}
+
    + ${files.map(file => `
  • ${language.$('releaseInfo.additionalFiles.file', { + file: linkFile(file), + size: 'pre-computed size' + })}
  • `).join('\n')} +
+ `).join('\n')} +
+ `; +} + // Artist strings export function getArtistString(artists, { diff --git a/src/page/album.js b/src/page/album.js index 5ea7c5a0..8df8a678 100644 --- a/src/page/album.js +++ b/src/page/album.js @@ -53,7 +53,8 @@ export function write(album, {wikiData}) { }`; }; - const commentaryEntries = [album, ...album.tracks].filter(x => x.commentary).length; + const hasCommentaryEntries = ([album, ...album.tracks].filter(x => x.commentary).length > 0); + const hasAdditionalFiles = (album.additionalFiles?.length > 0); const albumDuration = getTotalDuration(album.tracks); const listTag = getAlbumListTag(album); @@ -100,6 +101,8 @@ export function write(album, {wikiData}) { path: ['album', album.directory], page: ({ fancifyURL, + generateAdditionalFilesShortcut, + generateAdditionalFilesList, generateChronologyLinks, generateCoverLink, getAlbumCover, @@ -181,12 +184,15 @@ export function write(album, {wikiData}) { }) ].filter(Boolean).join('
\n')}

- ${commentaryEntries && `

${ - language.$('releaseInfo.viewCommentary', { - link: link.albumCommentary(album, { - text: language.$('releaseInfo.viewCommentary.link') + ${(hasAdditionalFiles || hasCommentaryEntries) && fixWS`

+ ${[ + hasAdditionalFiles && generateAdditionalFilesShortcut(album.additionalFiles, {language}), + hasCommentaryEntries && language.$('releaseInfo.viewCommentary', { + link: link.albumCommentary(album, { + text: language.$('releaseInfo.viewCommentary.link') + }) }) - }) + ].filter(Boolean).join('
\n') }

`} ${album.urls?.length && `

${ language.$('releaseInfo.listenOn', { @@ -212,6 +218,9 @@ export function write(album, {wikiData}) { ${album.tracks.map(trackToListItem).join('\n')} `} + ${hasAdditionalFiles && generateAdditionalFilesList(album.additionalFiles, { + linkFile: file => link.albumAdditionalFile({album, file}) + })} ${album.dateAddedToWiki && fixWS`

${[ diff --git a/src/strings-default.json b/src/strings-default.json index 1c5fbc68..78de7a89 100644 --- a/src/strings-default.json +++ b/src/strings-default.json @@ -98,6 +98,12 @@ "releaseInfo.artistCommentary": "Artist commentary:", "releaseInfo.artistCommentary.seeOriginalRelease": "See {ORIGINAL}!", "releaseInfo.artTags": "Tags:", + "releaseInfo.additionalFiles.shortcut": "{ANCHOR_LINK} {TITLES}", + "releaseInfo.additionalFiles.shortcut.anchorLink": "Additional files:", + "releaseInfo.additionalFiles.heading": "Has {FILE_COUNT} additional files:", + "releaseInfo.additionalFiles.entry": "{TITLE}", + "releaseInfo.additionalFiles.entry.withDescription": "{TITLE}: {DESCRIPTION}", + "releaseInfo.additionalFiles.file": "{FILE} ({SIZE})", "releaseInfo.note": "Note:", "trackList.group": "{GROUP} ({DURATION}):", "trackList.item.withDuration": "({DURATION}) {TRACK}", diff --git a/src/upd8.js b/src/upd8.js index bca6a0d0..b55ddda9 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -85,6 +85,8 @@ import { import { fancifyFlashURL, fancifyURL, + generateAdditionalFilesShortcut, + generateAdditionalFilesList, generateChronologyLinks, generateCoverLink, generateInfoGalleryLinks, @@ -1944,6 +1946,14 @@ async function main() { to }); + bound.generateAdditionalFilesShortcut = bindOpts(generateAdditionalFilesShortcut, { + language + }); + + bound.generateAdditionalFilesList = bindOpts(generateAdditionalFilesList, { + language + }); + bound.generateChronologyLinks = bindOpts(generateChronologyLinks, { link: bound.link, linkAnythingMan: bound.linkAnythingMan, diff --git a/src/url-spec.js b/src/url-spec.js index b9366b0d..c1ed1eba 100644 --- a/src/url-spec.js +++ b/src/url-spec.js @@ -76,6 +76,7 @@ const urlSpec = { trackCover: 'album-art/<>/<>.<>', artistAvatar: 'artist-avatar/<>.<>', flashArt: 'flash-art/<>.<>', + albumAdditionalFile: 'album-additional/<>/<>', } } }; diff --git a/src/util/link.js b/src/util/link.js index 4e611df5..68539621 100644 --- a/src/util/link.js +++ b/src/util/link.js @@ -94,6 +94,19 @@ const link = { tag: linkDirectory('tag'), track: linkDirectory('track', {expose: 'data-track'}), + // TODO: This is a bit hacky. Files are just strings (not objects), so we + // have to manually provide the album alongside the file. They also don't + // follow the usual {name: whatever} type shape, so we have to provide that + // ourselves. + _albumAdditionalFileHelper: linkHelper( + ((fakeFileObject, { to }) => + to('media.albumAdditionalFile', fakeFileObject.album.directory, fakeFileObject.name)), + {color: false}), + albumAdditionalFile: ({ file, album }, { to }) => link._albumAdditionalFileHelper({ + name: file, + album + }, {to}), + media: linkPathname('media.path', {color: false}), root: linkPathname('shared.path', {color: false}), data: linkPathname('data.path', {color: false}), -- cgit 1.3.0-6-gf8a5