File tree Expand file tree Collapse file tree 2 files changed +9
-11
lines changed
Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -32,16 +32,15 @@ module.exports = async function ssg({ output, cache }) {
3232 writeFileSync ( `${ target } .html` , content )
3333 }
3434
35- const instancesLookup = 'window.instances = ' ;
36- const instances = content . split ( "\n" ) . find ( ( line ) => line . indexOf ( instancesLookup ) > - 1 ) . split ( instancesLookup ) [ 1 ] . slice ( 0 , - 1 ) ;
35+ const stateLookup = '<meta name="nullstack" content="' ;
36+ const state = content . split ( "\n" ) . find ( ( line ) => line . indexOf ( stateLookup ) > - 1 ) . split ( stateLookup ) [ 1 ] . slice ( 0 , - 2 ) ;
37+ const { instances, page } = JSON . parse ( decodeURI ( state ) ) ;
3738
38- const pageLookup = 'window.page = ' ;
39- const page = content . split ( "\n" ) . find ( ( line ) => line . indexOf ( pageLookup ) > - 1 ) . split ( pageLookup ) [ 1 ] . slice ( 0 , - 1 ) ;
4039 if ( url !== `/nullstack/${ application . environment . key } /offline` && url !== '/404' ) {
41- pages [ url ] = JSON . parse ( page ) ;
40+ pages [ url ] = page ;
4241 }
4342
44- const json = `{"instances": ${ instances } , " page": ${ page } }` ;
43+ const json = JSON . stringify ( { instances, page } ) ;
4544 writeFileSync ( `${ target } /index.json` , json ) ;
4645
4746 const pattern = / h r e f = " ( .* ?) " / g;
Original file line number Diff line number Diff line change @@ -7,11 +7,10 @@ function withAPI(url) {
77
88async function extractData ( response ) {
99 const html = await response . clone ( ) . text ( ) ;
10- const instancesLookup = 'window.instances = ' ;
11- const instances = html . split ( "\n" ) . find ( ( line ) => line . indexOf ( instancesLookup ) > - 1 ) . split ( instancesLookup ) [ 1 ] . slice ( 0 , - 1 ) ;
12- const pageLookup = 'window.page = ' ;
13- const page = html . split ( "\n" ) . find ( ( line ) => line . indexOf ( pageLookup ) > - 1 ) . split ( pageLookup ) [ 1 ] . slice ( 0 , - 1 ) ;
14- const json = `{"instances": ${ instances } , "page": ${ page } }` ;
10+ const stateLookup = '<meta name="nullstack" content="' ;
11+ const state = html . split ( "\n" ) . find ( ( line ) => line . indexOf ( stateLookup ) > - 1 ) . split ( stateLookup ) [ 1 ] . slice ( 0 , - 2 ) ;
12+ const { instances, page } = JSON . parse ( decodeURI ( state ) ) ;
13+ const json = JSON . stringify ( { instances, page } ) ;
1514 return new Response ( json , {
1615 headers : { 'Content-Type' : 'application/json' }
1716 } ) ;
You can’t perform that action at this time.
0 commit comments