« 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/util/urls.js26
-rw-r--r--src/write/build-modes/live-dev-server.js20
-rw-r--r--src/write/build-modes/static-build.js20
3 files changed, 36 insertions, 30 deletions
diff --git a/src/util/urls.js b/src/util/urls.js
index 78bcd200..4672c6a2 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -137,6 +137,8 @@ export const thumb = {
   small: thumbnailHelper('.small'),
 };
 
+// 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,
 
@@ -184,6 +186,30 @@ export function getURLsFrom({
   };
 }
 
+// Makes the generally-used and wiki-specialized "absoluteTo" page utility.
+// "absoluteTo" returns an absolute path, starting at site root (/) leading
+// to the target.
+export function getURLsFromRoot({
+  baseDirectory,
+  urls,
+}) {
+  const from = urls.from('shared.root');
+
+  return (targetFullKey, ...args) => {
+    const [groupKey, subKey] = targetFullKey.split('.');
+    return (
+      '/' +
+      (groupKey === 'localized' && baseDirectory
+        ? from.to(
+            'localizedWithBaseDirectory.' + subKey,
+            baseDirectory,
+            ...args
+          )
+        : from.to(targetFullKey, ...args))
+    );
+  };
+}
+
 export function getPagePathname({
   baseDirectory,
   device = false,
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index a8e54247..d481b480 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -17,6 +17,7 @@ import {
   getPagePathname,
   getPageSubdirectoryPrefix,
   getURLsFrom,
+  getURLsFromRoot,
 } from '../../util/urls.js';
 
 import {
@@ -256,20 +257,10 @@ export async function go({
       }),
     });
 
-    const absoluteTo = (targetFullKey, ...args) => {
-      const [groupKey, subKey] = targetFullKey.split('.');
-      const from = urls.from('shared.root');
-      return (
-        '/' +
-        (groupKey === 'localized' && baseDirectory
-          ? from.to(
-              'localizedWithBaseDirectory.' + subKey,
-              baseDirectory,
-              ...args
-            )
-          : from.to(targetFullKey, ...args))
-      );
-    };
+    const absoluteTo = getURLsFromRoot({
+      baseDirectory,
+      urls,
+    });
 
     try {
       const pageSubKey = servePath[0];
@@ -314,7 +305,6 @@ export async function go({
         ...bound,
 
         absoluteTo,
-        relativeTo: to,
         to,
         urls,
 
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index 1544a122..c2bb02f2 100644
--- a/src/write/build-modes/static-build.js
+++ b/src/write/build-modes/static-build.js
@@ -30,6 +30,7 @@ import {
   getPagePaths,
   getPageSubdirectoryPrefix,
   getURLsFrom,
+  getURLsFromRoot,
 } from '../../util/urls.js';
 
 const pageFlags = Object.keys(pageSpecs);
@@ -302,20 +303,10 @@ export async function go({
           }),
         });
 
-        const absoluteTo = (targetFullKey, ...args) => {
-          const [groupKey, subKey] = targetFullKey.split('.');
-          const from = urls.from('shared.root');
-          return (
-            '/' +
-            (groupKey === 'localized' && baseDirectory
-              ? from.to(
-                  'localizedWithBaseDirectory.' + subKey,
-                  baseDirectory,
-                  ...args
-                )
-              : from.to(targetFullKey, ...args))
-          );
-        };
+        const absoluteTo = getURLsFromRoot({
+          baseDirectory,
+          urls,
+        });
 
         const bound = bindUtilities({
           language,
@@ -327,7 +318,6 @@ export async function go({
           ...bound,
 
           absoluteTo,
-          relativeTo: to,
           to,
           urls,