« get me outta code hell

fix random links bug caused by <base> changes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/client.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2020-06-29 15:35:29 -0300
committerFlorrie <towerofnix@gmail.com>2020-06-29 15:35:29 -0300
commit3e3cf5867ab1e6afff432a1daabf999d2eac246e (patch)
tree8e966485952dea58b8bcb94a0c887053e8a8a882 /client.js
parent4afad0df6aa435a50b4323604b16603ec43c7c50 (diff)
fix random links bug caused by <base> changes
this also adds a new track "Friendship Aneurysm" to Squiddles :P
Diffstat (limited to 'client.js')
-rw-r--r--client.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/client.js b/client.js
index ffdab814..1ae0a2d0 100644
--- a/client.js
+++ b/client.js
@@ -10,6 +10,15 @@ const fandomAlbumData = albumData.filter(album => album.isFanon);
 const artistNames = artistData.filter(artist => !artist.alias).map(artist => artist.name);
 const allTracks = C.getAllTracks(albumData);
 
+function rebase(href) {
+    const relative = document.documentElement.dataset.rebase;
+    if (relative) {
+        return relative + "/" + href;
+    } else {
+        return href;
+    }
+}
+
 function pick(array) {
     return array[Math.floor(Math.random() * array.length)];
 }
@@ -20,15 +29,15 @@ function getAlbum(el) {
 }
 
 function openAlbum(album) {
-    location.href = `${C.ALBUM_DIRECTORY}/${album.directory}/index.html`;
+    location.href = rebase(`${C.ALBUM_DIRECTORY}/${album.directory}/index.html`);
 }
 
 function openTrack(track) {
-    location.href = `${C.TRACK_DIRECTORY}/${track.directory}/index.html`;
+    location.href = rebase(`${C.TRACK_DIRECTORY}/${track.directory}/index.html`);
 }
 
 function openArtist(artist) {
-    location.href = `${C.ARTIST_DIRECTORY}/${C.getArtistDirectory(artist)}/index.html`;
+    location.href = rebase(`${C.ARTIST_DIRECTORY}/${C.getArtistDirectory(artist)}/index.html`);
 }
 
 for (const a of document.body.querySelectorAll('[data-random]')) {