diff options
Diffstat (limited to 'static')
| -rw-r--r-- | static/js/searchChange.js | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/static/js/searchChange.js b/static/js/searchChange.js index afe3214..8f776ae 100644 --- a/static/js/searchChange.js +++ b/static/js/searchChange.js @@ -1,11 +1,10 @@ const fs = require('fs'); const path = require("path"); -const replace = require('replace-in-file'); - // Path for config.toml const configTomlPath = path.join(__dirname, "../../config.toml"); async function main() { + const { replaceInFileSync } = await import('replace-in-file'); // Process arguments to determine the search mode const args = process.argv.slice(2); // Remove the first two default arguments @@ -14,11 +13,11 @@ async function main() { switch (args[0]) { case '--pagefind': console.log('Pagefind search mode activated.'); - await swapToPagefind(); + await swapToPagefind(replaceInFileSync); break; case '--elasticlunr': console.log('Elasticlunr search mode activated.'); - await swapToElasticlunr(); + await swapToElasticlunr(replaceInFileSync); break; default: console.log('Unknown search mode. Please use --pagefind or --elasticlunr.'); @@ -30,38 +29,38 @@ async function main() { main(); -async function swapToPagefind() { +async function swapToPagefind(replaceInFileSync) { // Edit the config.toml file - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /search_library = ['|"]\w+['|"]/g, to: 'search_library = "pagefind"', }); - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /online_indexformat = ['|"]\w+['|"]/g, to: 'online_indexformat = "fuse_json"', }); - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /index_format = ['|"]\w+['|"]/g, to: 'index_format = "fuse_json"', }); } -async function swapToElasticlunr() { +async function swapToElasticlunr(replaceInFileSync) { // Edit the config.toml file - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /search_library = ['|"]\w+['|"]/g, to: 'search_library = "elasticlunr"', }); - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /online_indexformat = ['|"]\w+['|"]/g, to: 'online_indexformat = "elasticlunr_json"', }); - replace.sync({ + replaceInFileSync({ files: configTomlPath, from: /index_format = ['|"]\w+['|"]/g, to: 'index_format = "elasticlunr_json"', |
