« 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/content/dependencies/generateAlbumCommentaryPage.js1
-rw-r--r--src/content/dependencies/linkAlbumDynamically.js20
-rw-r--r--src/util/replacer.js2
3 files changed, 20 insertions, 3 deletions
diff --git a/src/content/dependencies/generateAlbumCommentaryPage.js b/src/content/dependencies/generateAlbumCommentaryPage.js
index c14640af..61d9ca95 100644
--- a/src/content/dependencies/generateAlbumCommentaryPage.js
+++ b/src/content/dependencies/generateAlbumCommentaryPage.js
@@ -161,6 +161,7 @@ export default {
               language.encapsulate(entryCapsule, 'title.albumCommentary', titleCapsule =>
                 relations.albumCommentaryHeading.slots({
                   tag: 'h3',
+                  attributes: {id: 'album-commentary'},
                   color: data.color,
 
                   title:
diff --git a/src/content/dependencies/linkAlbumDynamically.js b/src/content/dependencies/linkAlbumDynamically.js
index 3adc64df..ca295b41 100644
--- a/src/content/dependencies/linkAlbumDynamically.js
+++ b/src/content/dependencies/linkAlbumDynamically.js
@@ -7,8 +7,24 @@ export default {
     infoLink: relation('linkAlbum', album),
   }),
 
-  generate: (relations, {pagePath}) =>
-    (pagePath[0] === 'albumGallery'
+  data: (album) => ({
+    albumDirectory:
+      album.directory,
+
+    albumHasCommentary:
+      !!album.commentary,
+  }),
+
+  generate: (data, relations, {pagePath}) =>
+    (pagePath[0] === 'albumCommentary' &&
+     pagePath[1] === data.albumDirectory &&
+     data.albumHasCommentary
+      ? relations.infoLink.slots({
+          anchor: true,
+          hash: 'album-commentary',
+        })
+
+   : pagePath[0] === 'albumGallery'
       ? relations.galleryLink
       : relations.infoLink),
 };
diff --git a/src/util/replacer.js b/src/util/replacer.js
index d1b0a269..9034cb9d 100644
--- a/src/util/replacer.js
+++ b/src/util/replacer.js
@@ -13,7 +13,7 @@ import {escapeRegex, typeAppearance} from '#sugar';
 export const replacerSpec = {
   'album': {
     find: 'album',
-    link: 'linkAlbum',
+    link: 'linkAlbumDynamically',
   },
 
   'album-commentary': {