« 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
path: root/src/write
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 /src/write
parentbfc26e34ece45983ecd96e44fe5a54a3e1d9adca (diff)
remove output-specific getPagePaths util
Diffstat (limited to 'src/write')
-rw-r--r--src/write/build-modes/static-build.js53
1 files changed, 29 insertions, 24 deletions
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index 90fc38ae..bbf97085 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));
 }