« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-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;