« get me outta code hell

remove THING_DIRECTORY constants once and for all - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-03-10 11:49:52 -0400
committer(quasar) nebula <towerofnix@gmail.com>2021-03-10 11:49:52 -0400
commit4ae47f11a7c2ab3b913d6298f24ef416e7f1d47f (patch)
tree89a299e59c12bc700cfaf2fc3380bf61b8a12778
parent082427cb1f48ce2b1c7e13f362499a5c58ca76ab (diff)
remove THING_DIRECTORY constants once and for all
replaced by urlSpec. nice! :D
-rw-r--r--common/common.js17
-rwxr-xr-xupd8.js26
2 files changed, 18 insertions, 25 deletions
diff --git a/common/common.js b/common/common.js
index 92dca10..56ee7b3 100644
--- a/common/common.js
+++ b/common/common.js
@@ -60,17 +60,12 @@ const C = {
     //
     // Upd8 03/11/2020: Oh my god this was a pain to re-align (copying from
     // udp8.js over to shared.js).
-    ALBUM_DIRECTORY: 'album',
-    TRACK_DIRECTORY: 'track',
-    ARTIST_DIRECTORY: 'artist',
-    ARTIST_AVATAR_DIRECTORY: 'artist-avatar',
-    TAG_DIRECTORY: 'tag',
-    LISTING_DIRECTORY: 'list',
-    FLASH_DIRECTORY: 'flash',
-    NEWS_DIRECTORY: 'news',
-    GROUP_DIRECTORY: 'group',
-    COMMENTARY_DIRECTORY: 'commentary',
-    JS_DISABLED_DIRECTORY: 'js-disabled',
+    //
+    // Upd8 03/10/2021 (wow, almost exactly a year later): This code comment
+    // from literally the first day of wiki development is finally no longer
+    // necessary! It was commenting constnats like "ALBUM_DIRECTORY" 8efore.
+    // 8ut we don't have those constants anymore, 'cuz urlSpec in upd8.js
+    // covers all that!
 
     UNRELEASED_TRACKS_DIRECTORY: 'unreleased-tracks',
     OFFICIAL_GROUP_DIRECTORY: 'official',
diff --git a/upd8.js b/upd8.js
index bbbaf49..49a9a39 100755
--- a/upd8.js
+++ b/upd8.js
@@ -287,7 +287,7 @@ function generateURLs(fromPath) {
     ));
 }
 
-const urls = Object.fromEntries(Object.entries(urlSpec.localized).map(
+const urls = Object.fromEntries(Object.entries({...urlSpec.localized, ...urlSpec.shared}).map(
     ([key, path]) => [key, generateURLs(path)]
 ));
 
@@ -2267,7 +2267,6 @@ function getFlashGridHTML({strings, to, ...props}) {
         strings,
         srcFn: flash => to.flashArt(flash.directory),
         hrefFn: flash => to.flash(flash.directory),
-        altFn: () => strings('misc.alt.flashArt'),
         ...props
     });
 }
@@ -2308,23 +2307,22 @@ function writeSymlinks() {
 }
 
 function writeSharedFilesAndPages({strings}) {
-    return progressPromiseAll(`Writing files & pages shared across languages.`, [
-        // THESE REDIRECT PAGES ARE TECH DEBT! Oops.
+    const redirect = async (title, from, urlKey, directory) => {
+        const target = path.relative(from, urls.root[urlKey](directory));
+        const content = generateRedirectPage(title, target, {strings});
+        await mkdirp(path.join(outputPath, from));
+        await writeFile(path.join(outputPath, from, 'index.html'), content);
+    };
 
+    return progressPromiseAll(`Writing files & pages shared across languages.`, [
         groupData?.some(group => group.directory === 'fandom') &&
-        mkdirp(path.join(outputPath, 'albums', 'fandom'))
-            .then(() => writeFile(path.join(outputPath, 'albums', 'fandom', 'index.html'),
-                generateRedirectPage('Fandom - Gallery', `/${C.GROUP_DIRECTORY}/fandom/gallery/`, {strings}))),
+        redirect('Fandom - Gallery', 'albums/fandom', 'groupGallery', 'fandom'),
 
         groupData?.some(group => group.directory === 'official') &&
-        mkdirp(path.join(outputPath, 'albums', 'official'))
-            .then(() => writeFile(path.join(outputPath, 'albums', 'official', 'index.html'),
-                generateRedirectPage('Official - Gallery', `/${C.GROUP_DIRECTORY}/official/gallery/`, {strings}))),
+        redirect('Official - Gallery', 'albums/official', 'groupGallery', 'official'),
 
         wikiInfo.features.listings &&
-        mkdirp(path.join(outputPath, C.LISTING_DIRECTORY, 'all-commentary'))
-            .then(() => writeFile(path.join(outputPath, C.LISTING_DIRECTORY, 'all-commentary', 'index.html'),
-                generateRedirectPage('Album Commentary', `/${C.COMMENTARY_DIRECTORY}/`, {strings}))),
+        redirect('Album Commentary', 'list/all-commentary', 'commentaryIndex', ''),
 
         writeFile(path.join(outputPath, 'data.json'), fixWS`
             {
@@ -3151,7 +3149,7 @@ function writeArtistPage(artist) {
                 content: fixWS`
                     ${avatarFileExists && generateCoverLink({
                         strings, to,
-                        src: `/${C.MEDIA_DIRECTORY}/${avatarPath}`,
+                        src: to.artistAvatar(artist.directory),
                         alt: strings('misc.alt.artistAvatar')
                     })}
                     <h1>${strings('artistPage.title', {artist: name})}</h1>