Skip to content

Commit aecfe6c

Browse files
committed
update mechanism
1 parent 8eea3d7 commit aecfe6c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ content/static/latest/
99
content/static/**/*.dtmp
1010
content/static/**/*.bkp
1111
content/static/**/*.crswap
12-
assets/json/lunr-index.json
12+
content/static/lunr-index.json

assets/js/generate-lunr-index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ const fs = require('fs');
22
const lunr = require('lunr');
33

44
const args = process.argv.slice(2);
5-
const destination = args[0] === undefined
6-
? "./docs"
7-
: args[0];
85

9-
const data = JSON.parse(fs.readFileSync(`${destination}/offline-search-index.json`));
6+
// Arguments should only be provided from a pipeline build.
7+
const isFromPipeline = args[0] !== undefined;
8+
9+
const source = isFromPipeline
10+
? args[0]
11+
: "./docs";
12+
13+
const destination = isFromPipeline
14+
? `${args[0]}`
15+
: "./docs";
16+
17+
const data = JSON.parse(fs.readFileSync(`${source}/offline-search-index.json`));
1018

1119
const idx = lunr(function () {
1220
this.ref('ref');
@@ -26,10 +34,14 @@ const idx = lunr(function () {
2634
});
2735
});
2836

37+
if (!isFromPipeline) {
38+
fs.writeFileSync(`./content/static/lunr-index.json`, JSON.stringify(idx));
39+
}
40+
2941
fs.writeFileSync(`${destination}/lunr-index.json`, JSON.stringify(idx));
3042

3143
// check if file got created
3244
if (!fs.existsSync(`${destination}/lunr-index.json`)) {
33-
console.error('Failed to create lunr index');
45+
console.error('Failed to create lunr index, hugo must be build using `hugo` command before running this script.');
3446
process.exit(1);
3547
}

0 commit comments

Comments
 (0)