« get me outta code hell

Merge branch 'data-steps' of github.com:hsmusic/hsmusic-wiki into data-steps - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/write/build-modes
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-08 21:21:16 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-08 21:21:16 -0300
commit2a6c0f4053d3bf1b774b34e55a1e3de487a1204c (patch)
treedbd7dc4af65f1c5717448a34eee46860bd20984f /src/write/build-modes
parent860453fa79802768ac0b4e19efa64d0be02ef66c (diff)
parent725482638dcc96632c3a9cf2b885f4128c50a1c1 (diff)
Merge branch 'data-steps' of github.com:hsmusic/hsmusic-wiki into data-steps
Diffstat (limited to 'src/write/build-modes')
-rw-r--r--src/write/build-modes/live-dev-server.js6
-rw-r--r--src/write/build-modes/static-build.js76
2 files changed, 39 insertions, 43 deletions
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index a87da27b..edee3267 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -321,6 +321,10 @@ export async function go({
 
     try {
       if (page.type === 'redirect') {
+        const title =
+          page.title ??
+          page.getTitle?.({language});
+
         const target = to('localized.' + page.toPath[0], ...page.toPath.slice(1));
 
         response.writeHead(301, {
@@ -328,7 +332,7 @@ export async function go({
           'Location': target,
         });
 
-        const redirectHTML = generateRedirectHTML(page.title, target, {language});
+        const redirectHTML = generateRedirectHTML(title, target, {language});
 
         response.end(redirectHTML);
 
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index bf722bff..4f074058 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);
-  }
 }