« get me outta code hell

Merge branch 'staging' into preview - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/page
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-02-05 09:36:50 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-02-05 09:36:50 -0400
commitf36f93b702729f14021746d56b192b25ac3ed1b7 (patch)
tree5bd2de31bf42627e76feff3823b6d1ff809c8a49 /src/page
parentdb93dfae3aa8a627451ee643e2c02291e4f5dead (diff)
parentf71136f0a03d7f3c36651918af2dc18527dd47be (diff)
Merge branch 'staging' into preview
Diffstat (limited to 'src/page')
-rw-r--r--src/page/album.js8
-rw-r--r--src/page/group.js25
2 files changed, 21 insertions, 12 deletions
diff --git a/src/page/album.js b/src/page/album.js
index 7a7f35bc..897e5110 100644
--- a/src/page/album.js
+++ b/src/page/album.js
@@ -55,7 +55,7 @@ export function write(album, {wikiData}) {
   const displayTrackSections =
     album.trackSections &&
       (album.trackSections.length > 1 ||
-        !album.trackSections[0].isDefaultTrackSection);
+        !album.trackSections[0]?.isDefaultTrackSection);
 
   const listTag = getAlbumListTag(album);
 
@@ -294,6 +294,7 @@ export function write(album, {wikiData}) {
                 })),
 
             displayTrackSections &&
+            !empty(album.trackSections) &&
               html.tag('dl',
                 {class: 'album-group-list'},
                 album.trackSections.flatMap(({
@@ -316,6 +317,7 @@ export function write(album, {wikiData}) {
                 ])),
 
             !displayTrackSections &&
+            !empty(album.tracks) &&
               html.tag(listTag,
                 album.tracks.map(trackToListItem)),
 
@@ -749,6 +751,10 @@ export function generateAlbumNavLinks(album, currentTrack, {
     randomLink,
   ].filter(Boolean);
 
+  if (empty(allLinks)) {
+    return '';
+  }
+
   return `(${language.formatUnitList(allLinks)})`;
 }
 
diff --git a/src/page/group.js b/src/page/group.js
index 37ebb789..9a48c1d8 100644
--- a/src/page/group.js
+++ b/src/page/group.js
@@ -18,8 +18,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) => ({
@@ -62,7 +61,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')),
@@ -120,7 +119,7 @@ export function write(group, {wikiData}) {
     }),
   };
 
-  const galleryPage = {
+  const galleryPage = !empty(group.albums) && {
     type: 'page',
     path: ['groupGallery', group.directory],
     page: ({
@@ -159,7 +158,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',
@@ -216,7 +215,7 @@ export function write(group, {wikiData}) {
     }),
   };
 
-  return [infoPage, galleryPage];
+  return [infoPage, galleryPage].filter(Boolean);
 }
 
 // Utility functions
@@ -234,8 +233,6 @@ function generateGroupSidebar(currentGroup, isGallery, {
     return null;
   }
 
-  const linkKey = isGallery ? 'groupGallery' : 'groupInfo';
-
   return {
     content: [
       html.tag('h1',
@@ -254,15 +251,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),
-                  })))),
+                  }));
+              })),
           ])),
     ],
   };