« get me outta code hell

compute subdirectoryPrefix internally - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-01-10 20:28:22 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-01-10 20:28:48 -0400
commitba8a441f95481e294d414a0c89e2513f82f45a7a (patch)
tree1d1a4ea96d7c209f16125346e8772034161a93e7
parent54ad9946e3fa32ae8388d54ec8b3baad78a29417 (diff)
compute subdirectoryPrefix internally
-rw-r--r--src/util/urls.js16
-rw-r--r--src/write/build-modes/live-dev-server.js6
-rw-r--r--src/write/build-modes/static-build.js11
3 files changed, 9 insertions, 24 deletions
diff --git a/src/util/urls.js b/src/util/urls.js
index 1c7d1c5..c2119b8 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -140,20 +140,16 @@ export const thumb = {
 // Makes the generally-used and wiki-specialized "to" page utility.
 // "to" returns a relative path from the current page to the target.
 export function getURLsFrom({
-  urls,
-
   baseDirectory,
   pagePath,
-  subdirectoryPrefix,
+  urls,
 }) {
   const pageSubKey = pagePath[0];
+  const subdirectoryPrefix = getPageSubdirectoryPrefix({pagePath});
 
   return (targetFullKey, ...args) => {
     const [groupKey, subKey] = targetFullKey.split('.');
-    let path = subdirectoryPrefix;
-
-    let from;
-    let to;
+    let from, to;
 
     // When linking to *outside* the localized area of the site, we need to
     // make sure the result is correctly relative to the 8ase directory.
@@ -182,9 +178,9 @@ export function getURLsFrom({
       to = targetFullKey;
     }
 
-    path += urls.from(from).to(to, ...args);
-
-    return path;
+    return (
+      subdirectoryPrefix +
+      urls.from(from).to(to, ...args));
   };
 }
 
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index ec9689b..a4c4c87 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -15,7 +15,6 @@ import {logInfo, logWarn, progressCallAll} from '../../util/cli.js';
 import {
   getPagePathname,
   getPagePathnameAcrossLanguages,
-  getPageSubdirectoryPrefix,
   getURLsFrom,
   getURLsFromRoot,
 } from '../../util/urls.js';
@@ -245,12 +244,9 @@ export async function go({
     } = urlToPageMap[pathnameKey];
 
     const to = getURLsFrom({
-      urls,
       baseDirectory,
       pagePath: servePath,
-      subdirectoryPrefix: getPageSubdirectoryPrefix({
-        pagePath: servePath,
-      }),
+      urls,
     });
 
     const absoluteTo = getURLsFromRoot({
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index 5141891..23c6470 100644
--- a/src/write/build-modes/static-build.js
+++ b/src/write/build-modes/static-build.js
@@ -28,7 +28,6 @@ import {
 import {
   getPagePathname,
   getPagePathnameAcrossLanguages,
-  getPageSubdirectoryPrefix,
   getURLsFrom,
   getURLsFromRoot,
 } from '../../util/urls.js';
@@ -281,12 +280,9 @@ export async function go({
         });
 
         const to = getURLsFrom({
-          urls,
           baseDirectory,
           pagePath,
-          subdirectoryPrefix: getPageSubdirectoryPrefix({
-            pagePath,
-          }),
+          urls,
         });
 
         const absoluteTo = getURLsFromRoot({
@@ -351,12 +347,9 @@ export async function go({
         });
 
         const to = getURLsFrom({
-          urls,
           baseDirectory,
           pagePath: fromPath,
-          subdirectoryPrefix: getPageSubdirectoryPrefix({
-            pagePath: fromPath,
-          }),
+          urls,
         });
 
         const target = to('localized.' + toPath[0], ...toPath.slice(1));