diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-26 15:20:48 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-31 12:11:44 -0300 |
commit | fa969b9dd99d18a3c5f77300a79a9c923ce280ce (patch) | |
tree | 52dcd1cc1e870c627975d7bff09542a7ecb3bacf /src/data | |
parent | d1b7f655df1918f04e013acbb4ec0eb36122c40b (diff) |
search, upd8: write index into wikiCachePath
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/things/search.js | 18 |
1 files changed, 14 insertions, 4 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.`; } |