« get me outta code hell

fallback "Track list" track group in album sidebar - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-05-27 12:18:42 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-05-27 12:18:42 -0300
commit789bf78f5c350a98bbf64cb7aa06af6c27aab110 (patch)
treee40b00a82875a89856bb09b84016b1956bfdf4f7
parentd57e22972213bf45eda1ffa0ba290b5bffffc195 (diff)
fallback "Track list" track group in album sidebar
-rw-r--r--src/strings-default.json1
-rwxr-xr-xsrc/upd8.js63
2 files changed, 33 insertions, 31 deletions
diff --git a/src/strings-default.json b/src/strings-default.json
index 031389eb..eac71544 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -150,6 +150,7 @@
     "homepage.title": "{TITLE}",
     "homepage.news.title": "News",
     "homepage.news.entry.viewRest": "(View rest of entry!)",
+    "albumSidebar.trackList.fallbackGroupName": "Track list",
     "albumSidebar.trackList.group": "{GROUP}",
     "albumSidebar.trackList.group.withRange": "{GROUP} ({RANGE})",
     "albumSidebar.trackList.item": "{TRACK}",
diff --git a/src/upd8.js b/src/upd8.js
index 35f7d6ed..5615bb1c 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -5234,6 +5234,13 @@ function generateSidebarForAlbum(album, {
 }) {
     const listTag = getAlbumListTag(album);
 
+    const trackGroups = album.trackGroups || [{
+        name: strings('albumSidebar.trackList.fallbackGroupName'),
+        color: album.color,
+        startIndex: 0,
+        tracks: album.tracks
+    }];
+
     const trackToListItem = track => `<li ${classes(track === currentTrack && 'current')}>${
         strings('albumSidebar.trackList.item', {
             track: link.track(track)
@@ -5242,37 +5249,31 @@ function generateSidebarForAlbum(album, {
 
     const trackListPart = fixWS`
         <h1>${link.album(album)}</h1>
-        ${(album.trackGroups
-            ? album.trackGroups.map(({ name, color, startIndex, tracks }) =>
-                html.tag('details', {
-                    // Leave side8ar track groups collapsed on al8um homepage,
-                    // since there's already a view of all the groups expanded
-                    // in the main content area.
-                    open: currentTrack && tracks.includes(currentTrack),
-                    class: tracks.includes(currentTrack) && 'current'
-                }, [
-                    html.tag('summary',
-                        {style: getLinkThemeString(color)},
-                        (listTag === 'ol'
-                            ? strings('albumSidebar.trackList.group.withRange', {
-                                group: `<span class="group-name">${name}</span>`,
-                                range: `${startIndex + 1}&ndash;${startIndex + tracks.length}`
-                            })
-                            : strings('albumSidebar.trackList.group', {
-                                group: `<span class="group-name">${name}</span>`
-                            }))
-                    ),
-                    fixWS`
-                        <${listTag === 'ol' ? `ol start="${startIndex + 1}"` : listTag}>
-                            ${tracks.map(trackToListItem).join('\n')}
-                        </${listTag}>
-                    `
-                ])).join('\n')
-            : fixWS`
-                <${listTag}>
-                    ${album.tracks.map(trackToListItem).join('\n')}
-                </${listTag}>
-            `)}
+        ${trackGroups.map(({ name, color, startIndex, tracks }) =>
+            html.tag('details', {
+                // Leave side8ar track groups collapsed on al8um homepage,
+                // since there's already a view of all the groups expanded
+                // in the main content area.
+                open: currentTrack && tracks.includes(currentTrack),
+                class: tracks.includes(currentTrack) && 'current'
+            }, [
+                html.tag('summary',
+                    {style: getLinkThemeString(color)},
+                    (listTag === 'ol'
+                        ? strings('albumSidebar.trackList.group.withRange', {
+                            group: `<span class="group-name">${name}</span>`,
+                            range: `${startIndex + 1}&ndash;${startIndex + tracks.length}`
+                        })
+                        : strings('albumSidebar.trackList.group', {
+                            group: `<span class="group-name">${name}</span>`
+                        }))
+                ),
+                fixWS`
+                    <${listTag === 'ol' ? `ol start="${startIndex + 1}"` : listTag}>
+                        ${tracks.map(trackToListItem).join('\n')}
+                    </${listTag}>
+                `
+            ])).join('\n')}
     `;
 
     const { groups } = album;