« get me outta code hell

most essential behavior for live-dev-server - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-01-09 21:07:16 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-01-09 21:07:16 -0400
commit594e8dd46f9e6cc74c680536a1d820eef27133f0 (patch)
treeb4dfeda6e32dfb09df6d3c6c52cccf88bf824005 /src/util
parent154c050db72ebf06d4514326c696ab43fb3f8dc8 (diff)
most essential behavior for live-dev-server
Diffstat (limited to 'src/util')
-rw-r--r--src/util/urls.js56
1 files changed, 35 insertions, 21 deletions
diff --git a/src/util/urls.js b/src/util/urls.js
index f05f134b..69ff1d7e 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -142,11 +142,11 @@ export function getURLsFrom({
 
   baseDirectory,
   pageSubKey,
-  paths,
+  subdirectoryPrefix,
 }) {
   return (targetFullKey, ...args) => {
     const [groupKey, subKey] = targetFullKey.split('.');
-    let path = paths.subdirectoryPrefix;
+    let path = subdirectoryPrefix;
 
     let from;
     let to;
@@ -184,32 +184,47 @@ export function getURLsFrom({
   };
 }
 
-export function getPagePaths({
-  outputPath,
+export function getPagePathname({
+  baseDirectory,
+  fullKey,
+  urlArgs,
   urls,
+}) {
+  const [groupKey, subKey] = fullKey.split('.');
 
+  return (groupKey === 'localized' && baseDirectory
+    ? urls
+        .from('shared.root')
+        .toDevice(
+          'localizedWithBaseDirectory.' + subKey,
+          baseDirectory,
+          ...urlArgs)
+    : urls
+        .from('shared.root')
+        .toDevice(fullKey, ...urlArgs));
+}
+
+// Needed for the rare path arguments which themselves contains one or more
+// slashes, e.g. for listings, with arguments like 'albums/by-name'.
+export function getPageSubdirectoryPrefix({urlArgs}) {
+  return '../'.repeat(urlArgs.join('/').split('/').length - 1);
+}
+
+export function getPagePaths({
   baseDirectory,
   fullKey,
+  outputPath,
   urlArgs,
+  urls,
 }) {
   const [groupKey, subKey] = fullKey.split('.');
 
-  const pathname =
-    groupKey === 'localized' && baseDirectory
-      ? urls
-          .from('shared.root')
-          .toDevice(
-            'localizedWithBaseDirectory.' + subKey,
-            baseDirectory,
-            ...urlArgs)
-      : urls
-          .from('shared.root')
-          .toDevice(fullKey, ...urlArgs);
-
-  // Needed for the rare path arguments which themselves contains one or more
-  // slashes, e.g. for listings, with arguments like 'albums/by-name'.
-  const subdirectoryPrefix =
-    '../'.repeat(urlArgs.join('/').split('/').length - 1);
+  const pathname = getPagePathname({
+    baseDirectory,
+    fullKey,
+    urlArgs,
+    urls,
+  });
 
   const outputDirectory = path.join(outputPath, pathname);
 
@@ -224,6 +239,5 @@ export function getPagePaths({
 
     output,
     pathname,
-    subdirectoryPrefix,
   };
 }