« 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/page/group.js25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/page/group.js b/src/page/group.js
index 6bfd1532..f9af8e80 100644
--- a/src/page/group.js
+++ b/src/page/group.js
@@ -16,8 +16,7 @@ export function targets({wikiData}) {
 export function write(group, {wikiData}) {
   const {listingSpec, wikiInfo} = wikiData;
 
-  const {albums} = group;
-  const tracks = albums.flatMap((album) => album.tracks);
+  const tracks = group.albums.flatMap((album) => album.tracks);
   const totalDuration = getTotalDuration(tracks, {originalReleasesOnly: true});
 
   const albumLines = group.albums.map((album) => ({
@@ -65,7 +64,7 @@ export function write(group, {wikiData}) {
               transformMultiline(group.description)),
 
           ...html.fragment(
-            group.albums && [
+            !empty(group.albums) && [
               html.tag('h2',
                 {class: ['content-heading']},
                 language.$('groupInfoPage.albumList.title')),
@@ -123,7 +122,7 @@ export function write(group, {wikiData}) {
     }),
   };
 
-  const galleryPage = {
+  const galleryPage = !empty(group.albums) && {
     type: 'page',
     path: ['groupGallery', group.directory],
     page: ({
@@ -165,7 +164,7 @@ export function write(group, {wikiData}) {
                   unit: true,
                 })),
               albums: html.tag('b',
-                language.countAlbums(albums.length, {
+                language.countAlbums(group.albums.length, {
                   unit: true,
                 })),
               time: html.tag('b',
@@ -222,7 +221,7 @@ export function write(group, {wikiData}) {
     }),
   };
 
-  return [infoPage, galleryPage];
+  return [infoPage, galleryPage].filter(Boolean);
 }
 
 // Utility functions
@@ -240,8 +239,6 @@ function generateGroupSidebar(currentGroup, isGallery, {
     return null;
   }
 
-  const linkKey = isGallery ? 'groupGallery' : 'groupInfo';
-
   return {
     content: [
       html.tag('h1',
@@ -260,15 +257,21 @@ function generateGroupSidebar(currentGroup, isGallery, {
                 category: `<span class="group-name">${category.name}</span>`,
               })),
             html.tag('ul',
-              category.groups.map((group) =>
-                html.tag('li',
+              category.groups.map((group) => {
+                const linkKey = (
+                  isGallery && !empty(group.albums)
+                    ? 'groupGallery'
+                    : 'groupInfo');
+
+                return html.tag('li',
                   {
                     class: group === currentGroup && 'current',
                     style: getLinkThemeString(group.color),
                   },
                   language.$('groupSidebar.groupList.item', {
                     group: link[linkKey](group),
-                  })))),
+                  }));
+              })),
           ])),
     ],
   };