« get me outta code hell

don't pass around fullKey where unneeded - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-01-10 19:54:10 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-01-10 19:54:10 -0400
commitfd59ddd05bdfebf2f9a55a0fa5915485929e7de6 (patch)
treec66b4b8e03fee9cf87ff41ceee1c1763992a0a5e /src
parente06292fe8e7d789d38ac43fd9eee6816e39e18fe (diff)
don't pass around fullKey where unneeded
Diffstat (limited to 'src')
-rw-r--r--src/util/urls.js22
-rw-r--r--src/write/build-modes/live-dev-server.js7
-rw-r--r--src/write/build-modes/static-build.js7
3 files changed, 11 insertions, 25 deletions
diff --git a/src/util/urls.js b/src/util/urls.js
index ead6c769..0733ce04 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -213,24 +213,14 @@ export function getURLsFromRoot({
 export function getPagePathname({
   baseDirectory,
   device = false,
-  fullKey,
+  pageSubKey,
   urlArgs,
   urls,
 }) {
-  const [groupKey, subKey] = fullKey.split('.');
-
-  const toKey = device ? 'toDevice' : 'to';
-
-  return (groupKey === 'localized' && baseDirectory
-    ? urls
-        .from('shared.root')[toKey](
-          'localizedWithBaseDirectory.' + subKey,
-          baseDirectory,
-          ...urlArgs)
-    : urls
-        .from('shared.root')[toKey](
-          fullKey,
-          ...urlArgs));
+  const to = urls.from('shared.root')[device ? 'toDevice' : 'to'];
+  return (baseDirectory
+    ? to('localizedWithBaseDirectory.' + pageSubKey, baseDirectory, ...urlArgs)
+    : to('localized.' + pageSubKey, ...urlArgs));
 }
 
 export function getPagePathnameAcrossLanguages({
@@ -249,7 +239,7 @@ export function getPagePathnameAcrossLanguages({
           (language === defaultLanguage
             ? ''
             : language.code),
-        fullKey: 'localized.' + pageSubKey,
+        pageSubKey,
         urlArgs,
         urls,
       }),
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index a5d9da97..bdd4561e 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -83,17 +83,14 @@ export async function go({
       else if (page.type === 'redirect')
         servePath = page.fromPath;
 
-      const fullKey = 'localized.' + servePath[0];
-      const urlArgs = servePath.slice(1);
-
       return Object.values(languages).map(language => {
         const baseDirectory =
           language === defaultLanguage ? '' : language.code;
 
         const pathname = getPagePathname({
           baseDirectory,
-          fullKey,
-          urlArgs,
+          pageSubKey: servePath[0],
+          urlArgs: servePath.slice(1),
           urls,
         });
 
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index 0e8c4b07..edfb02c2 100644
--- a/src/write/build-modes/static-build.js
+++ b/src/write/build-modes/static-build.js
@@ -267,7 +267,6 @@ export async function go({
       ...pageWrites.map(page => () => {
         const pageSubKey = page.path[0];
         const urlArgs = page.path.slice(1);
-        const fullKey = 'localized.' + pageSubKey;
 
         const localizedPathnames = getPagePathnameAcrossLanguages({
           defaultLanguage,
@@ -279,7 +278,7 @@ export async function go({
 
         const pathname = getPagePathname({
           baseDirectory,
-          fullKey,
+          pageSubKey,
           urlArgs,
           urls,
         });
@@ -345,7 +344,7 @@ export async function go({
           outputDirectory: path.join(outputPath, getPagePathname({
             baseDirectory,
             device: true,
-            fullKey,
+            pageSubKey,
             urlArgs,
             urls,
           })),
@@ -373,7 +372,7 @@ export async function go({
           outputDirectory: path.join(outputPath, getPagePathname({
             baseDirectory,
             device: true,
-            fullKey: 'localized.' + fromPath[0],
+            pageSubKey: fromPath[0],
             urlArgs: fromPath.slice(1),
             urls,
           })),