« get me outta code hell

remove output-specific getPagePaths util - 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:32:22 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-01-10 19:32:22 -0400
commit592acc152dc68e0f24300c090c9eabb9f21cef6b (patch)
tree9f0c4033f4e18743659b251013b0bec14cdd87fe
parentbfc26e34ece45983ecd96e44fe5a54a3e1d9adca (diff)
remove output-specific getPagePaths util
-rw-r--r--src/util/urls.js33
-rw-r--r--src/write/build-modes/static-build.js53
2 files changed, 29 insertions, 57 deletions
diff --git a/src/util/urls.js b/src/util/urls.js
index 4672c6a..a74e0df 100644
--- a/src/util/urls.js
+++ b/src/util/urls.js
@@ -238,36 +238,3 @@ export function getPagePathname({
 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 = getPagePathname({
-    baseDirectory,
-    device: true,
-    fullKey,
-    urlArgs,
-    urls,
-  });
-
-  const outputDirectory = path.join(outputPath, pathname);
-
-  const output = {
-    directory: outputDirectory,
-    documentHTML: path.join(outputDirectory, 'index.html'),
-    oEmbedJSON: path.join(outputDirectory, 'oembed.json'),
-  };
-
-  return {
-    urlPath: [fullKey, ...urlArgs],
-
-    output,
-    pathname,
-  };
-}
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index 90fc38a..bbf9708 100644
--- a/src/write/build-modes/static-build.js
+++ b/src/write/build-modes/static-build.js
@@ -27,7 +27,6 @@ import {
 
 import {
   getPagePathname,
-  getPagePaths,
   getPageSubdirectoryPrefix,
   getURLsFrom,
   getURLsFromRoot,
@@ -267,6 +266,7 @@ export async function go({
       ...pageWrites.map(page => () => {
         const pageSubKey = page.path[0];
         const urlArgs = page.path.slice(1);
+        const fullKey = 'localized.' + pageSubKey;
 
         const localizedPathnames = withEntries(languages, entries => entries
           .filter(([key, language]) => key !== 'default' && !language.hidden)
@@ -277,19 +277,17 @@ export async function go({
                 (language === defaultLanguage
                   ? ''
                   : language.code),
-              fullKey: 'localized.' + pageSubKey,
+              fullKey,
               urlArgs,
               urls,
             }),
           ]));
 
-        const paths = getPagePaths({
-          outputPath,
-          urls,
-
+        const pathname = getPagePathname({
           baseDirectory,
-          fullKey: 'localized.' + pageSubKey,
+          fullKey,
           urlArgs,
+          urls,
         });
 
         const to = getURLsFrom({
@@ -328,7 +326,7 @@ export async function go({
           wikiData.wikiInfo.canonicalBase +
             urls
               .from('shared.root')
-              .to('shared.path', paths.pathname + 'oembed.json');
+              .to('shared.path', pathname + 'oembed.json');
 
         const pageHTML = generateDocumentHTML(pageInfo, {
           cachebust,
@@ -340,7 +338,7 @@ export async function go({
           localizedPathnames,
           oEmbedJSONHref,
           pageSubKey,
-          pathname: paths.pathname,
+          pathname,
           to,
           transformMultiline: bound.transformMultiline,
           urlArgs,
@@ -350,7 +348,13 @@ export async function go({
         return writePage({
           html: pageHTML,
           oEmbedJSON,
-          paths,
+          outputDirectory: path.join(outputPath, getPagePathname({
+            baseDirectory,
+            device: true,
+            fullKey,
+            urlArgs,
+            urls,
+          })),
         });
       }),
       ...redirectWrites.map(({fromPath, toPath, title: titleFn}) => () => {
@@ -358,15 +362,6 @@ export async function go({
           language,
         });
 
-        const from = getPagePaths({
-          outputPath,
-          urls,
-
-          baseDirectory,
-          fullKey: 'localized.' + fromPath[0],
-          urlArgs: fromPath.slice(1),
-        });
-
         const to = getURLsFrom({
           urls,
           baseDirectory,
@@ -378,7 +373,17 @@ export async function go({
 
         const target = to('localized.' + toPath[0], ...toPath.slice(1));
         const html = generateRedirectHTML(title, target, {language});
-        return writePage({html, paths: from});
+
+        return writePage({
+          html,
+          outputDirectory: path.join(outputPath, getPagePathname({
+            baseDirectory,
+            device: true,
+            fullKey: 'localized.' + fromPath[0],
+            urlArgs: fromPath.slice(1),
+            urls,
+          })),
+        });
       }),
     ], queueSize));
   };
@@ -424,15 +429,15 @@ import {
 async function writePage({
   html,
   oEmbedJSON = '',
-  paths,
+  outputDirectory,
 }) {
-  await mkdir(paths.output.directory, {recursive: true});
+  await mkdir(outputDirectory, {recursive: true});
 
   await Promise.all([
-    writeFile(paths.output.documentHTML, html),
+    writeFile(path.join(outputDirectory, 'index.html'), html),
 
     oEmbedJSON &&
-      writeFile(paths.output.oEmbedJSON, oEmbedJSON),
+      writeFile(path.join(outputDirectory, 'oembed.json'), oEmbedJSON),
   ].filter(Boolean));
 }