1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
const fs = require('fs');
const path = require("path");
// 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
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(replaceInFileSync);
break;
case '--elasticlunr':
console.log('Elasticlunr search mode activated.');
await swapToElasticlunr(replaceInFileSync);
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(replaceInFileSync) {
// Edit the config.toml file
replaceInFileSync({
files: configTomlPath,
from: /search_library = ['|"]\w+['|"]/g,
to: 'search_library = "pagefind"',
});
replaceInFileSync({
files: configTomlPath,
from: /online_indexformat = ['|"]\w+['|"]/g,
to: 'online_indexformat = "fuse_json"',
});
replaceInFileSync({
files: configTomlPath,
from: /index_format = ['|"]\w+['|"]/g,
to: 'index_format = "fuse_json"',
});
}
async function swapToElasticlunr(replaceInFileSync) {
// Edit the config.toml file
replaceInFileSync({
files: configTomlPath,
from: /search_library = ['|"]\w+['|"]/g,
to: 'search_library = "elasticlunr"',
});
replaceInFileSync({
files: configTomlPath,
from: /online_indexformat = ['|"]\w+['|"]/g,
to: 'online_indexformat = "elasticlunr_json"',
});
replaceInFileSync({
files: configTomlPath,
from: /index_format = ['|"]\w+['|"]/g,
to: 'index_format = "elasticlunr_json"',
});
}
|