« get me outta code hell

polish up album & album extras nav - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-12-21 20:09:17 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-12-21 20:09:17 -0400
commitf215bf15ae61f9ad08f8992cbf273f0b1d0ff6a0 (patch)
treeae79cc87f853762eac7d02059fbd368f73c91b0c /src
parent9412fefa5d53af171a91bd3b8ce958d35a7f87d7 (diff)
polish up album & album extras nav
Diffstat (limited to 'src')
-rw-r--r--src/misc-templates.js9
-rw-r--r--src/page/album-commentary.js23
-rw-r--r--src/page/album.js137
-rw-r--r--src/strings-default.json2
-rwxr-xr-xsrc/upd8.js6
5 files changed, 122 insertions, 55 deletions
diff --git a/src/misc-templates.js b/src/misc-templates.js
index 5d082703..5dd96492 100644
--- a/src/misc-templates.js
+++ b/src/misc-templates.js
@@ -676,6 +676,7 @@ function unbound_generateNavigationLinks(current, {
   data,
   isMain = true,
   linkKey = 'anything',
+  returnAsArray = false,
 }) {
   let previousLink, nextLink;
 
@@ -713,11 +714,13 @@ function unbound_generateNavigationLinks(current, {
     ...additionalLinks,
   ].filter(Boolean);
 
-  if (!links.length) {
+  if (returnAsArray) {
+    return links;
+  } else if (empty(links)) {
     return '';
+  } else {
+    return language.formatUnitList(links);
   }
-
-  return language.formatUnitList(links);
 }
 
 // Sticky heading, ooooo
diff --git a/src/page/album-commentary.js b/src/page/album-commentary.js
index b67dab0d..74eee2b0 100644
--- a/src/page/album-commentary.js
+++ b/src/page/album-commentary.js
@@ -1,5 +1,6 @@
 // Album commentary page and index specifications.
 
+import {generateAlbumExtrasPageNav} from './album.js';
 import {accumulateSum} from '../util/sugar.js';
 import {filterAlbumsByCommentary} from '../util/wiki-data.js';
 
@@ -38,7 +39,7 @@ export function write(album) {
         content: html.tag('div', {class: 'long-content'}, [
           generateStickyHeadingContainer({
             title: language.$('albumCommentaryPage.title', {
-              album: link.album(album),
+              album: album.name,
             }),
           }),
 
@@ -70,21 +71,11 @@ export function write(album) {
         ]),
       },
 
-      nav: {
-        linkContainerClasses: ['nav-links-hierarchy'],
-        links: [
-          {toHome: true},
-          {
-            path: ['localized.commentaryIndex'],
-            title: language.$('commentaryIndex.title'),
-          },
-          {
-            html: language.$('albumCommentaryPage.nav.album', {
-              album: link.albumCommentary(album, {class: 'current'}),
-            }),
-          },
-        ],
-      },
+      nav: generateAlbumExtrasPageNav(album, 'commentary', {
+        html,
+        language,
+        link,
+      }),
     }),
   };
 
diff --git a/src/page/album.js b/src/page/album.js
index ab44e656..fb738db8 100644
--- a/src/page/album.js
+++ b/src/page/album.js
@@ -47,14 +47,9 @@ export function write(album, {wikiData}) {
           }));
   };
 
-  const hasCommentaryEntries =
-    !empty([album, ...album.tracks].filter((x) => x.commentary));
   const hasAdditionalFiles = !empty(album.additionalFiles);
   const albumDuration = getTotalDuration(album.tracks);
 
-  // TODO: code this obviously
-  const hasGalleryPage = true;
-
   const displayTrackGroups =
     album.trackGroups &&
       (album.trackGroups.length > 1 ||
@@ -237,14 +232,14 @@ export function write(album, {wikiData}) {
                 hasAdditionalFiles &&
                   generateAdditionalFilesShortcut(album.additionalFiles),
 
-                hasGalleryPage &&
+                checkGalleryPage(album) &&
                   language.$('releaseInfo.viewGallery', {
                     link: link.albumGallery(album, {
                       text: language.$('releaseInfo.viewGallery.link'),
                     }),
                   }),
 
-                hasCommentaryEntries &&
+                checkCommentaryPage(album) &&
                   language.$('releaseInfo.viewCommentary', {
                     link: link.albumCommentary(album, {
                       text: language.$('releaseInfo.viewCommentary.link'),
@@ -343,12 +338,16 @@ export function write(album, {wikiData}) {
                 album: link.album(album, {class: 'current'}),
               }),
             },
+            {
+              divider: false,
+              html: generateAlbumNavLinks(album, null, {
+                generateNavigationLinks,
+                html,
+                language,
+                link,
+              }),
+            }
           ],
-          bottomRowContent: generateAlbumNavLinks(album, null, {
-            generateNavigationLinks,
-            html,
-            language,
-          }),
           content: generateAlbumChronologyLinks(album, null, {
             generateChronologyLinks,
             html,
@@ -373,6 +372,7 @@ export function write(album, {wikiData}) {
       // generateInfoGalleryLinks,
       // generateNavigationLinks,
       getAlbumCover,
+      getAlbumStylesheet,
       getGridHTML,
       getTrackCover,
       // getLinkThemeString,
@@ -382,6 +382,7 @@ export function write(album, {wikiData}) {
       link,
     }) => ({
       title: language.$('albumGalleryPage.title', {album: album.name}),
+      stylesheet: getAlbumStylesheet(album),
 
       themeColor: album.color,
       theme: getThemeString(album.color),
@@ -429,6 +430,12 @@ export function write(album, {wikiData}) {
             })),
         ],
       },
+
+      nav: generateAlbumExtrasPageNav(album, 'gallery', {
+        html,
+        language,
+        link,
+      }),
     }),
   };
 
@@ -634,35 +641,101 @@ export function generateAlbumSecondaryNav(album, currentTrack, {
   };
 }
 
+function checkGalleryPage(_album) {
+  return true;
+}
+
+function checkCommentaryPage(album) {
+  return !empty([album, ...album.tracks].filter((x) => x.commentary));
+}
+
 export function generateAlbumNavLinks(album, currentTrack, {
   generateNavigationLinks,
   html,
   language,
+  link,
+
+  currentExtra = null,
+  showTrackNavigation = true,
+  showExtraLinks = null,
 }) {
   const isTrackPage = !!currentTrack;
 
-  if (album.tracks.length <= 1) {
-    return '';
-  }
+  showExtraLinks ??= currentTrack ? false : true;
+
+  const extraLinks = showExtraLinks ? [
+    checkGalleryPage(album) &&
+      link.albumGallery(album, {
+        class: [currentExtra === 'gallery' && 'current'],
+        text: language.$('albumPage.nav.gallery'),
+      }),
+
+    checkCommentaryPage(album) &&
+      link.albumCommentary(album, {
+        class: [currentExtra === 'commentary' && 'current'],
+        text: language.$('albumPage.nav.commentary'),
+      }),
+  ].filter(Boolean) : [];
+
+  const previousNextLinks =
+    showTrackNavigation &&
+    album.tracks.length > 1 &&
+      generateNavigationLinks(currentTrack, {
+        data: album.tracks,
+        linkKey: 'track',
+        returnAsArray: true,
+      })
+
+  const randomLink =
+    showTrackNavigation &&
+    album.tracks.length > 1 &&
+      html.tag('a',
+        {
+          href: '#',
+          'data-random': 'track-in-album',
+          id: 'random-button'
+        },
+        (isTrackPage
+          ? language.$('trackPage.nav.random')
+          : language.$('albumPage.nav.randomTrack')));
 
-  const randomLink = html.tag('a',
-    {
-      href: '#',
-      'data-random': 'track-in-album',
-      id: 'random-button'
-    },
-    (isTrackPage
-      ? language.$('trackPage.nav.random')
-      : language.$('albumPage.nav.randomTrack')));
-
-  const navigationLinks =
-    generateNavigationLinks(currentTrack, {
-      additionalLinks: [randomLink],
-      data: album.tracks,
-      linkKey: 'track',
-    });
+  const allLinks = [
+    ...previousNextLinks || [],
+    ...extraLinks || [],
+    randomLink,
+  ].filter(Boolean);
+
+  return `(${language.formatUnitList(allLinks)})`;
+}
+
+export function generateAlbumExtrasPageNav(album, currentExtra, {
+  html,
+  language,
+  link,
+}) {
+  return {
+    linkContainerClasses: ['nav-links-hierarchy'],
+    links: [
+      {toHome: true},
+      {
+        html: language.$('albumPage.nav.album', {
+          album: link.album(album, {class: 'current'}),
+        }),
+      },
+      {
+        divider: false,
+        html: generateAlbumNavLinks(album, null, {
+          currentExtra,
+          showTrackNavigation: false,
+          showExtraLinks: true,
 
-  return `(${navigationLinks})`;
+          html,
+          language,
+          link,
+        }),
+      }
+    ],
+  };
 }
 
 export function generateAlbumChronologyLinks(album, currentTrack, {
diff --git a/src/strings-default.json b/src/strings-default.json
index 4990bd11..ab08cdca 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -200,6 +200,8 @@
   "albumPage.title": "{ALBUM}",
   "albumPage.nav.album": "{ALBUM}",
   "albumPage.nav.randomTrack": "Random Track",
+  "albumPage.nav.gallery": "Gallery",
+  "albumPage.nav.commentary": "Commentary",
   "albumGalleryPage.title": "{ALBUM} - Gallery",
   "albumGalleryPage.infoLine": "{TRACKS} totaling {DURATION}.",
   "albumGalleryPage.infoLine.withDate": "{TRACKS} totaling {DURATION}. Released {DATE}.",
diff --git a/src/upd8.js b/src/upd8.js
index 0de724f2..20b0d28b 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -1068,10 +1068,6 @@ export function generateDocumentHTML(pageInfo, {
     let partContent;
 
     if (typeof cur.html === 'string') {
-      if (!cur.html) {
-        logWarn`Empty HTML in nav link ${JSON.stringify(cur)}`;
-        console.trace();
-      }
       partContent = cur.html;
     } else {
       const attributes = {
@@ -1099,6 +1095,8 @@ export function generateDocumentHTML(pageInfo, {
       partContent = html.tag('a', attributes, linkTitle);
     }
 
+    if (!partContent) continue;
+
     const part = html.tag('span',
       {class: cur.divider === false && 'no-divider'},
       partContent);