« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/misc-templates.js34
-rw-r--r--src/page/album.js21
-rw-r--r--src/strings-default.json6
-rwxr-xr-xsrc/upd8.js10
-rw-r--r--src/url-spec.js1
-rw-r--r--src/util/link.js13
6 files changed, 79 insertions, 6 deletions
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: `<a href="#additional-files">${language.$('releaseInfo.additionalFiles.shortcut.anchorLink')}</a>`,
+        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`
+        <p id="additional-files">${language.$('releaseInfo.additionalFiles.heading', {fileCount})}</p>
+        <dl>
+            ${additionalFiles.map(({ title, description, files }) => fixWS`
+                <dt>${(description
+                    ? language.$('releaseInfo.additionalFiles.entry.withDescription', {title, description})
+                    : language.$('releaseInfo.additionalFiles.entry', {title}))}</dt>
+                <dd><ul>
+                    ${files.map(file => `<li>${language.$('releaseInfo.additionalFiles.file', {
+                        file: linkFile(file),
+                        size: '<i>pre-computed size</i>'
+                    })}</li>`).join('\n')}
+                </ul></dd>
+            `).join('\n')}
+        </dl>
+    `;
+}
+
 // 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}) {
         }</li>`;
     };
 
-    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('<br>\n')}
                         </p>
-                        ${commentaryEntries && `<p>${
-                            language.$('releaseInfo.viewCommentary', {
-                                link: link.albumCommentary(album, {
-                                    text: language.$('releaseInfo.viewCommentary.link')
+                        ${(hasAdditionalFiles || hasCommentaryEntries) && fixWS`<p>
+                            ${[
+                                hasAdditionalFiles && generateAdditionalFilesShortcut(album.additionalFiles, {language}),
+                                hasCommentaryEntries && language.$('releaseInfo.viewCommentary', {
+                                    link: link.albumCommentary(album, {
+                                        text: language.$('releaseInfo.viewCommentary.link')
+                                    })
                                 })
-                            })
+                            ].filter(Boolean).join('<br>\n')
                         }</p>`}
                         ${album.urls?.length && `<p>${
                             language.$('releaseInfo.listenOn', {
@@ -212,6 +218,9 @@ export function write(album, {wikiData}) {
                                 ${album.tracks.map(trackToListItem).join('\n')}
                             </${listTag}>
                         `}
+                        ${hasAdditionalFiles && generateAdditionalFilesList(album.additionalFiles, {
+                            linkFile: file => link.albumAdditionalFile({album, file})
+                        })}
                         ${album.dateAddedToWiki && fixWS`
                             <p>
                                 ${[
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}),