« get me outta code hell

extract fn for localizedPathnames - 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 19:45:13 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-01-10 19:45:32 -0400
commite06292fe8e7d789d38ac43fd9eee6816e39e18fe (patch)
treeb640471c8d401df418d94af6b8bfc3ce3e81c1ec
parent592acc152dc68e0f24300c090c9eabb9f21cef6b (diff)
extract fn for localizedPathnames
-rw-r--r--src/util/urls.js23
-rw-r--r--src/write/build-modes/live-dev-server.js23
-rw-r--r--src/write/build-modes/static-build.js24
3 files changed, 40 insertions, 30 deletions
diff --git a/src/util/urls.js b/src/util/urls.js
index a74e0dfb..ead6c769 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -233,6 +233,29 @@ export function getPagePathname({
           ...urlArgs));
 }
 
+export function getPagePathnameAcrossLanguages({
+  defaultLanguage,
+  languages,
+  pageSubKey,
+  urlArgs,
+  urls,
+}) {
+  return withEntries(languages, entries => entries
+    .filter(([key, language]) => key !== 'default' && !language.hidden)
+    .map(([_key, language]) => [
+      language.code,
+      getPagePathname({
+        baseDirectory:
+          (language === defaultLanguage
+            ? ''
+            : language.code),
+        fullKey: 'localized.' + pageSubKey,
+        urlArgs,
+        urls,
+      }),
+    ]));
+}
+
 // 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}) {
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index b6bf662b..a5d9da97 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -11,10 +11,10 @@ import {serializeThings} from '../../data/serialize.js';
 import * as pageSpecs from '../../page/index.js';
 
 import {logInfo, logWarn, progressCallAll} from '../../util/cli.js';
-import {withEntries} from '../../util/sugar.js';
 
 import {
   getPagePathname,
+  getPagePathnameAcrossLanguages,
   getPageSubdirectoryPrefix,
   getURLsFrom,
   getURLsFromRoot,
@@ -280,20 +280,13 @@ export async function go({
 
       response.writeHead(200, contentTypeHTML);
 
-      const localizedPathnames = withEntries(languages, entries => entries
-        .filter(([key, language]) => key !== 'default' && !language.hidden)
-        .map(([_key, language]) => [
-          language.code,
-          getPagePathname({
-            baseDirectory:
-              (language === defaultLanguage
-                ? ''
-                : language.code),
-            fullKey: 'localized.' + pageSubKey,
-            urlArgs,
-            urls,
-          }),
-        ]));
+      const localizedPathnames = getPagePathnameAcrossLanguages({
+        defaultLanguage,
+        languages,
+        pageSubKey,
+        urlArgs,
+        urls,
+      });
 
       const bound = bindUtilities({
         absoluteTo,
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index bbf97085..0e8c4b07 100644
--- a/src/write/build-modes/static-build.js
+++ b/src/write/build-modes/static-build.js
@@ -15,7 +15,7 @@ import {serializeThings} from '../../data/serialize.js';
 import * as pageSpecs from '../../page/index.js';
 
 import link from '../../util/link.js';
-import {empty, queue, withEntries} from '../../util/sugar.js';
+import {empty, queue} from '../../util/sugar.js';
 
 import {
   logError,
@@ -27,6 +27,7 @@ import {
 
 import {
   getPagePathname,
+  getPagePathnameAcrossLanguages,
   getPageSubdirectoryPrefix,
   getURLsFrom,
   getURLsFromRoot,
@@ -268,20 +269,13 @@ export async function go({
         const urlArgs = page.path.slice(1);
         const fullKey = 'localized.' + pageSubKey;
 
-        const localizedPathnames = withEntries(languages, entries => entries
-          .filter(([key, language]) => key !== 'default' && !language.hidden)
-          .map(([_key, language]) => [
-            language.code,
-            getPagePathname({
-              baseDirectory:
-                (language === defaultLanguage
-                  ? ''
-                  : language.code),
-              fullKey,
-              urlArgs,
-              urls,
-            }),
-          ]));
+        const localizedPathnames = getPagePathnameAcrossLanguages({
+          defaultLanguage,
+          languages,
+          pageSubKey,
+          urlArgs,
+          urls,
+        });
 
         const pathname = getPagePathname({
           baseDirectory,