« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/urls.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/urls.js')
-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 f05f134..69ff1d7 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,
   };
 }