aboutsummaryrefslogtreecommitdiff
path: root/static/js/searchChange.js
diff options
context:
space:
mode:
authorHysterelius2024-07-21 01:33:32 +1000
committerGitHub2024-07-20 08:33:32 -0700
commita7244a2983538f373c0af2ecfa4d6377584b8063 (patch)
treebc06b67d37ca88a5bbe938353f639cd28bef4d8d /static/js/searchChange.js
parent4dab5b9538f76cd56f53e6a68f34f505234e30ed (diff)
downloadabridge-a7244a2983538f373c0af2ecfa4d6377584b8063.tar.gz
abridge-a7244a2983538f373c0af2ecfa4d6377584b8063.tar.bz2
abridge-a7244a2983538f373c0af2ecfa4d6377584b8063.zip
Add pagefind search to abridge (#179)
* Start process of adding pagefind to abridge * Write to static to make index appear in public * Add multilingual support * Minify files and fix running in script * Add pagefind files * Add loading of pagefind data * Update gitignore to remove pagefind index files * Get basic search result surfacing working * Remove duplicate entries in search results * Sanitise except to remove unnecessary details * Finalise addition of pagefind * Add missing await * Fix config.toml and remove old files on rebuild * Finish chores on pagefind addition
Diffstat (limited to 'static/js/searchChange.js')
-rw-r--r--static/js/searchChange.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/static/js/searchChange.js b/static/js/searchChange.js
new file mode 100644
index 0000000..afe3214
--- /dev/null
+++ b/static/js/searchChange.js
@@ -0,0 +1,69 @@
+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() {
+ // Process arguments to determine the search mode
+ const args = process.argv.slice(2); // Remove the first two default arguments
+
+ if (args.length > 0) {
+ // Check the search mode based on the argument provided
+ switch (args[0]) {
+ case '--pagefind':
+ console.log('Pagefind search mode activated.');
+ await swapToPagefind();
+ break;
+ case '--elasticlunr':
+ console.log('Elasticlunr search mode activated.');
+ await swapToElasticlunr();
+ break;
+ default:
+ console.log('Unknown search mode. Please use --pagefind or --elasticlunr.');
+ }
+ } else {
+ console.log('No search mode specified. Please use --pagefind or --elasticlunr.');
+ }
+}
+
+main();
+
+async function swapToPagefind() {
+ // Edit the config.toml file
+ replace.sync({
+ files: configTomlPath,
+ from: /search_library = ['|"]\w+['|"]/g,
+ to: 'search_library = "pagefind"',
+ });
+ replace.sync({
+ files: configTomlPath,
+ from: /online_indexformat = ['|"]\w+['|"]/g,
+ to: 'online_indexformat = "fuse_json"',
+ });
+ replace.sync({
+ files: configTomlPath,
+ from: /index_format = ['|"]\w+['|"]/g,
+ to: 'index_format = "fuse_json"',
+ });
+}
+
+async function swapToElasticlunr() {
+ // Edit the config.toml file
+ replace.sync({
+ files: configTomlPath,
+ from: /search_library = ['|"]\w+['|"]/g,
+ to: 'search_library = "elasticlunr"',
+ });
+ replace.sync({
+ files: configTomlPath,
+ from: /online_indexformat = ['|"]\w+['|"]/g,
+ to: 'online_indexformat = "elasticlunr_json"',
+ });
+ replace.sync({
+ files: configTomlPath,
+ from: /index_format = ['|"]\w+['|"]/g,
+ to: 'index_format = "elasticlunr_json"',
+ });
+} \ No newline at end of file