Skip to content

Commit

Permalink
Fix 404 handling in navaid.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed May 1, 2020
1 parent ec7bff8 commit 73f0b0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 44 deletions.
34 changes: 12 additions & 22 deletions defaults/layout/ejected/router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,28 @@
allNodes = nodes;
function draw(m) {
node = getNode(uri);
route = m.default;
window.scrollTo(0, 0);
}
function track(obj) {
uri = obj.state || obj.uri;
/*
if (window.ga) ga.send('pageview', { dp:uri });
node = getNode(uri);
if (node === undefined) {
node = {
"path": "/404",
"type": "404",
"filename": "404.json"
"filename": "404.json",
"fields": {}
}
handle404(node);
}
allNodes = nodes;
*/
route = m.default;
window.scrollTo(0, 0);
}
function track(obj) {
uri = obj.state || obj.uri;
}
addEventListener('replacestate', track);
addEventListener('pushstate', track);
addEventListener('popstate', track);
const handle404 = node => {
if (node.filename == "404.json") {
import('../content/404.js').then(draw);
}
}
const router = Navaid('/', handle404(node));
const router = Navaid('/', () => import('../content/404.js').then(draw));
allNodes.forEach(node => {
router.on(node.path, () => {
Expand All @@ -63,8 +51,10 @@
} else {
import('../content/' + node.type + '.js').then(draw);
}
}).listen();
});
});
router.listen();
</script>
34 changes: 12 additions & 22 deletions generated/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,40 +315,28 @@ export default app;
allNodes = nodes;
function draw(m) {
node = getNode(uri);
route = m.default;
window.scrollTo(0, 0);
}
function track(obj) {
uri = obj.state || obj.uri;
/*
if (window.ga) ga.send('pageview', { dp:uri });
node = getNode(uri);
if (node === undefined) {
node = {
"path": "/404",
"type": "404",
"filename": "404.json"
"filename": "404.json",
"fields": {}
}
handle404(node);
}
allNodes = nodes;
*/
route = m.default;
window.scrollTo(0, 0);
}
function track(obj) {
uri = obj.state || obj.uri;
}
addEventListener('replacestate', track);
addEventListener('pushstate', track);
addEventListener('popstate', track);
const handle404 = node => {
if (node.filename == "404.json") {
import('../content/404.js').then(draw);
}
}
const router = Navaid('/', handle404(node));
const router = Navaid('/', () => import('../content/404.js').then(draw));
allNodes.forEach(node => {
router.on(node.path, () => {
Expand All @@ -359,10 +347,12 @@ export default app;
} else {
import('../content/' + node.type + '.js').then(draw);
}
}).listen();
});
});
router.listen();
</script>
`),
"/layout/global/footer.svelte": []byte(`<script>
Expand Down

0 comments on commit 73f0b0c

Please sign in to comment.