File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,4 @@ content/static/latest/
99content /static /** /* .dtmp
1010content /static /** /* .bkp
1111content /static /** /* .crswap
12- assets / json /lunr-index.json
12+ content / static /lunr-index.json
Original file line number Diff line number Diff line change @@ -2,11 +2,19 @@ const fs = require('fs');
22const lunr = require ( 'lunr' ) ;
33
44const 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
1119const 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+
2941fs . writeFileSync ( `${ destination } /lunr-index.json` , JSON . stringify ( idx ) ) ;
3042
3143// check if file got created
3244if ( ! 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}
You can’t perform that action at this time.
0 commit comments