« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data/things/search.js18
-rwxr-xr-xsrc/upd8.js33
2 files changed, 35 insertions, 16 deletions
diff --git a/src/data/things/search.js b/src/data/things/search.js
index ad641c38..ed65cb6b 100644
--- a/src/data/things/search.js
+++ b/src/data/things/search.js
@@ -1,15 +1,20 @@
-#!/usr/bin/env node
-
 'use strict';
 
 import {writeFile} from 'node:fs/promises';
+import * as path from 'node:path';
 
 import FlexSearch from 'flexsearch';
 
 import {logError, logInfo, logWarn} from '#cli';
 import Thing from '#thing';
 
-export async function writeSearchIndex(searchIndexPath, wikiData) {
+export async function writeSearchIndex({
+  wikiCachePath,
+  wikiData,
+}) {
+  if (!wikiCachePath) {
+    throw new Error(`Expected wikiCachePath to write into`);
+  }
 
   // Basic flow is:
   // 1. Define schema for type
@@ -81,5 +86,10 @@ export async function writeSearchIndex(searchIndexPath, wikiData) {
         });
       }));
 
-  await writeFile(searchIndexPath, JSON.stringify(searchData));
+  const outputFile =
+    path.join(wikiCachePath, 'search-index.json');
+
+  await writeFile(outputFile, JSON.stringify(searchData));
+
+  logInfo`Search index successfully written.`;
 }
diff --git a/src/upd8.js b/src/upd8.js
index 17fd7d7c..473a9514 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -769,14 +769,23 @@ async function main() {
       buildConfig: 'webRoutes',
     });
 
-    fallbackStep('buildSearchIndex', {
-      default: 'perform',
-      buildConfig: 'search',
-      cli: {
-        flag: 'skip-search',
-        negate: true,
-      },
-    });
+    if (wikiCachePath) {
+      fallbackStep('buildSearchIndex', {
+        default: 'perform',
+        buildConfig: 'search',
+        cli: {
+          flag: 'skip-search',
+          negate: true,
+        },
+      });
+    } else {
+      logInfo`No wiki cache provided, so not writing search index.`;
+
+      Object.assign(stepStatusSummary.buildSearchIndex, {
+        status: STATUS_NOT_APPLICABLE,
+        annotation: `no wiki cache to write into`,
+      });
+    }
 
     fallbackStep('verifyImagePaths', {
       default: 'perform',
@@ -1480,10 +1489,10 @@ async function main() {
       timeStart: Date.now(),
     });
 
-    const searchIndexPath = path.join(mediaPath, "search_index.json");
-    logInfo`Search index: ${searchIndexPath}`;
-
-    await writeSearchIndex(searchIndexPath, wikiData);
+    await writeSearchIndex({
+      wikiCachePath,
+      wikiData,
+    });
 
     Object.assign(stepStatusSummary.buildSearchIndex, {
       status: STATUS_DONE_CLEAN,