« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/write/build-modes/static-build.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/write/build-modes/static-build.js')
-rw-r--r--src/write/build-modes/static-build.js76
1 files changed, 34 insertions, 42 deletions
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index bf722bf..4f07405 100644
--- a/src/write/build-modes/static-build.js
+++ b/src/write/build-modes/static-build.js
@@ -78,6 +78,36 @@ export function getCLIOptions() {
   };
 }
 
+function generateRedirectHTML(title, target, {language}) {
+  return `<!DOCTYPE html>\n` + html.tag('html', [
+    html.tag('head', [
+      html.tag('title', language.$('redirectPage.title', {title})),
+      html.tag('meta', {charset: 'utf-8'}),
+
+      html.tag('meta', {
+        'http-equiv': 'refresh',
+        content: `0;url=${target}`,
+      }),
+
+      // TODO: Is this OK for localized pages?
+      html.tag('link', {
+        rel: 'canonical',
+        href: target,
+      }),
+    ]),
+
+    html.tag('body',
+      html.tag('main', [
+        html.tag('h1',
+          language.$('redirectPage.title', {title})),
+        html.tag('p',
+          language.$('redirectPage.infoLine', {
+            target: html.tag('a', {href: target}, target),
+          })),
+      ])),
+  ]);
+}
+
 export async function go({
   cliOptions,
   _dataPath,
@@ -124,6 +154,8 @@ export async function go({
   const writeAll = empty(selectedPageFlags) || selectedPageFlags.includes('all');
   logInfo`Writing site pages: ${writeAll ? 'all' : selectedPageFlags.join(', ')}`;
 
+  await mkdir(outputPath, {recursive: true});
+
   await writeSymlinks({
     srcRootPath,
     mediaPath,
@@ -323,11 +355,8 @@ export async function go({
         });
       }),
 
-      /*
-      ...redirectWrites.map(({fromPath, toPath, title: titleFn}) => () => {
-        const title = titleFn({
-          language,
-        });
+      ...redirectWrites.map(({fromPath, toPath, title, getTitle}) => () => {
+        title ??= getTitle?.({language});
 
         const to = getURLsFrom({
           baseDirectory,
@@ -348,7 +377,6 @@ export async function go({
           })),
         });
       }),
-      */
     ], queueSize));
   };
 
@@ -473,45 +501,9 @@ async function writeSharedFilesAndPages({
   const {groupData, wikiInfo} = wikiData;
 
   return progressPromiseAll(`Writing files & pages shared across languages.`, [
-    /*
-    groupData?.some((group) => group.directory === 'fandom') &&
-      redirect(
-        'Fandom - Gallery',
-        'albums/fandom',
-        'localized.groupGallery',
-        'fandom'
-      ),
-
-    groupData?.some((group) => group.directory === 'official') &&
-      redirect(
-        'Official - Gallery',
-        'albums/official',
-        'localized.groupGallery',
-        'official'
-      ),
-
-    wikiInfo.enableListings &&
-      redirect(
-        'Album Commentary',
-        'list/all-commentary',
-        'localized.commentaryIndex',
-        ''
-      ),
-    */
-
     wikiDataJSON &&
       writeFile(
         path.join(outputPath, 'data.json'),
         wikiDataJSON),
   ].filter(Boolean));
-
-  async function redirect(title, from, urlKey, directory) {
-    const target = path.relative(
-      from,
-      urls.from('shared.root').to(urlKey, directory)
-    );
-    const content = generateRedirectHTML(title, target, {language});
-    await mkdir(path.join(outputPath, from), {recursive: true});
-    await writeFile(path.join(outputPath, from, 'index.html'), content);
-  }
 }