« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/linkAlbumDynamically.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/linkAlbumDynamically.js')
-rw-r--r--src/content/dependencies/linkAlbumDynamically.js39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/content/dependencies/linkAlbumDynamically.js b/src/content/dependencies/linkAlbumDynamically.js
index ca295b41..7173b417 100644
--- a/src/content/dependencies/linkAlbumDynamically.js
+++ b/src/content/dependencies/linkAlbumDynamically.js
@@ -1,10 +1,21 @@
 export default {
-  contentDependencies: ['linkAlbumGallery', 'linkAlbum'],
-  extraDependencies: ['pagePath'],
+  contentDependencies: [
+    'linkAlbumCommentary',
+    'linkAlbumGallery',
+    'linkAlbum',
+  ],
+
+  extraDependencies: ['html', 'pagePath'],
 
   relations: (relation, album) => ({
-    galleryLink: relation('linkAlbumGallery', album),
-    infoLink: relation('linkAlbum', album),
+    galleryLink:
+      relation('linkAlbumGallery', album),
+
+    infoLink:
+      relation('linkAlbum', album),
+
+    commentaryLink:
+      relation('linkAlbumCommentary', album),
   }),
 
   data: (album) => ({
@@ -15,7 +26,17 @@ export default {
       !!album.commentary,
   }),
 
-  generate: (data, relations, {pagePath}) =>
+  slots: {
+    linkCommentaryPages: {
+      type: 'boolean',
+      default: false,
+    },
+  },
+
+  generate: (data, relations, slots, {pagePath}) =>
+     // When linking to an album *from* an album commentary page,
+     // if the link is to the *same* album, then the effective target
+     // of the link is really the album's commentary, so scroll to it.
     (pagePath[0] === 'albumCommentary' &&
      pagePath[1] === data.albumDirectory &&
      data.albumHasCommentary
@@ -24,7 +45,15 @@ export default {
           hash: 'album-commentary',
         })
 
+     // When linking to *another* album from an album commentary page,
+     // the target is (by default) still just the album (its info page).
+     // But this can be customized per-link!
+   : pagePath[0] === 'albumCommentary' &&
+     slots.linkCommentaryPages
+      ? relations.commentaryLink
+
    : pagePath[0] === 'albumGallery'
       ? relations.galleryLink
+
       : relations.infoLink),
 };