Skip to content

Commit

Permalink
Use pretty urls for spa routes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Apr 29, 2020
1 parent 947a811 commit 76af7a3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/build/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func DataSource(buildPath string, siteConfig readers.SiteConfig) (string, string
}

// Add trailing slash.
path = path + "/"
//path = path + "/"

// Check for index.json outside of type declaration.
if contentType == "index.json" {
Expand Down
14 changes: 6 additions & 8 deletions defaults/layout/ejected/router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
let route, node, allNodes;
const getNode = (uri, removeTrailingSlash = false) => {
if (removeTrailingSlash) {
return nodes.find(node => node.path.replace(/\/$/, "") == uri);
}
return nodes.find(node => node.path == uri);
const getNode = (uri, trailingSlash = "") => {
return nodes.find(node => node.path + trailingSlash == uri);
}
let uri = location.pathname;
node = getNode(uri);
if (node === undefined) {
node = getNode(uri, "/");
}
allNodes = nodes;
function draw(m) {
Expand All @@ -28,9 +28,6 @@
if (window.ga) ga.send('pageview', { dp:uri });
node = getNode(uri);
if (node === undefined) {
node = getNode(uri, true);
}
allNodes = nodes;
}
Expand All @@ -42,6 +39,7 @@
allNodes.forEach(node => {
router.on(node.path, () => import('../content/' + node.type + '.js').then(draw)).listen();
router.on(node.path+"/", () => import('../content/' + node.type + '.js').then(draw)).listen();
});
</script>
14 changes: 6 additions & 8 deletions generated/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ export default app;
let route, node, allNodes;
const getNode = (uri, removeTrailingSlash = false) => {
if (removeTrailingSlash) {
return nodes.find(node => node.path.replace(/\/$/, "") == uri);
}
return nodes.find(node => node.path == uri);
const getNode = (uri, trailingSlash = "") => {
return nodes.find(node => node.path + trailingSlash == uri);
}
let uri = location.pathname;
node = getNode(uri);
if (node === undefined) {
node = getNode(uri, "/");
}
allNodes = nodes;
function draw(m) {
Expand All @@ -324,9 +324,6 @@ export default app;
if (window.ga) ga.send('pageview', { dp:uri });
node = getNode(uri);
if (node === undefined) {
node = getNode(uri, true);
}
allNodes = nodes;
}
Expand All @@ -338,6 +335,7 @@ export default app;
allNodes.forEach(node => {
router.on(node.path, () => import('../content/' + node.type + '.js').then(draw)).listen();
router.on(node.path+"/", () => import('../content/' + node.type + '.js').then(draw)).listen();
});
</script>
Expand Down

0 comments on commit 76af7a3

Please sign in to comment.