Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions builders/ssg.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ module.exports = async function ssg({ output, cache }) {
writeFileSync(`${target}.html`, content)
}

const instancesLookup = 'window.instances = ';
const instances = content.split("\n").find((line) => line.indexOf(instancesLookup) > -1).split(instancesLookup)[1].slice(0, -1);
const stateLookup = '<meta name="nullstack" content="';
const state = content.split("\n").find((line) => line.indexOf(stateLookup) > -1).split(stateLookup)[1].slice(0, -2);
const { instances, page } = JSON.parse(decodeURI(state));

const pageLookup = 'window.page = ';
const page = content.split("\n").find((line) => line.indexOf(pageLookup) > -1).split(pageLookup)[1].slice(0, -1);
if (url !== `/nullstack/${application.environment.key}/offline` && url !== '/404') {
pages[url] = JSON.parse(page);
pages[url] = page;
}

const json = `{"instances": ${instances}, "page": ${page}}`;
const json = JSON.stringify({ instances, page });
writeFileSync(`${target}/index.json`, json);

const pattern = /href="(.*?)"/g;
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function server(env, argv) {
nodeArgs: ['--enable-source-maps'],
quiet: true
})
]) : undefined;
]) : [];
return {
mode: argv.environment,
entry: './server.js',
Expand Down
9 changes: 4 additions & 5 deletions workers/staticHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ function withAPI(url) {

async function extractData(response) {
const html = await response.clone().text();
const instancesLookup = 'window.instances = ';
const instances = html.split("\n").find((line) => line.indexOf(instancesLookup) > -1).split(instancesLookup)[1].slice(0, -1);
const pageLookup = 'window.page = ';
const page = html.split("\n").find((line) => line.indexOf(pageLookup) > -1).split(pageLookup)[1].slice(0, -1);
const json = `{"instances": ${instances}, "page": ${page}}`;
const stateLookup = '<meta name="nullstack" content="';
const state = html.split("\n").find((line) => line.indexOf(stateLookup) > -1).split(stateLookup)[1].slice(0, -2);
const { instances, page } = JSON.parse(decodeURI(state));
const json = JSON.stringify({ instances, page });
return new Response(json, {
headers: { 'Content-Type': 'application/json' }
});
Expand Down