@@ -19,22 +19,26 @@ function readFile(path) {
1919 return fs . readFileSync ( path , { encoding : "utf-8" } ) ;
2020}
2121
22- // Parse inputs.
23- const db = [ ] ;
22+ // Variables and constants.
23+ let search = [ ] ;
24+ let nav = [ ] ;
2425
2526const repo = process . argv [ 2 ] ;
2627const prefix = process . argv [ 3 ] ;
2728
28- const output = `dist/${ repo } /db.json` ;
29+ const searchOutput = `dist/${ repo } /search-db.json` ;
30+ const navOutput = `obj/${ repo } /nav-db.json` ;
31+
32+ // Parse inputs.
2933const inputs = process . argv . slice ( 4 ) ;
3034
3135for ( const input of inputs ) {
32- // Initialize entry and push it to database.
36+ // Initialize entry and push it to search database.
3337 const entry = {
3438 path : input
3539 } ;
3640
37- db . push ( entry ) ;
41+ search . push ( entry ) ;
3842
3943 // Generate link.
4044 const href = input . substring ( 15 + prefix . length , input . length - 3 ) ;
@@ -50,7 +54,27 @@ for (const input of inputs) {
5054 } else {
5155 entry . title = entry . href ;
5256 }
57+
58+ // Push to navigation database without the `content` field.
59+ const navEntry = structuredClone ( entry ) ;
60+ delete navEntry . content ;
61+
62+ nav . push ( navEntry ) ;
5363}
5464
65+ // Stringify.
66+ search = JSON . stringify ( search ) ;
67+ nav = JSON . stringify ( nav ) ;
68+
5569// Write database to disk.
56- fs . writeFileSync ( output , JSON . stringify ( db ) ) ;
70+ fs . writeFileSync ( searchOutput , search ) ;
71+
72+ // Write navigation data to disk only if there were changes.
73+ if ( fs . existsSync ( navOutput ) ) {
74+ const oldContent = readFile ( navOutput ) ;
75+ if ( oldContent !== nav ) {
76+ fs . writeFileSync ( navOutput , nav ) ;
77+ }
78+ } else {
79+ fs . writeFileSync ( navOutput , nav ) ;
80+ }
0 commit comments