Skip to content

Commit

Permalink
Allow empty hash for cleaner default URLs on the home screen (#349)
Browse files Browse the repository at this point in the history
This makes sure we don't need the #home hash for the default page URL.
  • Loading branch information
camillobruni authored Jan 17, 2024
1 parent 64a5e7c commit 4b451d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion resources/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ section {
border-radius: 20px;
}

section:target {
section:target,
body:not(body:has(section:target)) #home {
display: block;
}

Expand Down
22 changes: 17 additions & 5 deletions resources/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,32 @@ class MainBenchmarkClient {

_showSection(hash) {
if (this._isRunning) {
window.location.hash = "#running";
this._setLocationHash("#running");
return;
} else if (this._hasResults) {
if (hash !== "#summary" && hash !== "#details") {
window.location.hash = "#summary";
this._setLocationHash("#summary");
return;
}
} else {
if (hash !== "#home" && hash !== "#about") {
window.location.hash = "#home";
if (hash !== "" && hash !== "#home" && hash !== "#about") {
this._setLocationHash("#home");
return;
}
}
window.location.hash = hash || "#home";
this._setLocationHash(hash);
}

_setLocationHash(hash) {
if (hash === "#home" || hash === "")
this._removeLocationHash();
else
window.location.hash = hash;
}

_removeLocationHash() {
const location = window.location;
window.history.pushState("", document.title, location.pathname + location.search);
}
}

Expand Down

0 comments on commit 4b451d8

Please sign in to comment.