Skip to content

Commit 638a968

Browse files
authored
Update document title (#354)
Use a "data-title" attribute for each section to update document.title.
1 parent b0a465d commit 638a968

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</div>
5050
</section>
5151

52-
<section id="summary">
52+
<section id="summary" data-title="Results Summary">
5353
<a href="#home" class="logo">
5454
<img srcset="resources/[email protected] 2x" src="resources/logo.png" alt="Speedometer" />
5555
<div class="version">3.0</div>
@@ -69,7 +69,7 @@ <h1>Score</h1>
6969
</div>
7070
</section>
7171

72-
<section id="details">
72+
<section id="details" data-title="Results Details">
7373
<a href="#home" class="logo">
7474
<img srcset="resources/[email protected] 2x" src="resources/logo.png" alt="Speedometer" />
7575
<div class="version">3.0</div>
@@ -103,7 +103,7 @@ <h2>Detailed Metrics</h2>
103103
</div>
104104
</section>
105105

106-
<section id="about">
106+
<section id="about" data-title="About">
107107
<a href="#home" class="logo">
108108
<img srcset="resources/[email protected] 2x" src="resources/logo.png" alt="Speedometer" />
109109
<div class="version">3.0</div>

resources/main.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,18 @@ class MainBenchmarkClient {
351351
if (hash === "#home" || hash === "") {
352352
if (window.location.hash !== hash)
353353
window.location.hash = "#home";
354+
hash = "#home";
354355
this._removeLocationHash();
355356
} else {
356357
window.location.hash = hash;
357358
}
359+
this._updateDocumentTitle(hash);
360+
}
361+
362+
_updateDocumentTitle(hash) {
363+
const maybeSection = document.querySelector(hash);
364+
const sectionTitle = maybeSection?.getAttribute("data-title") ?? "";
365+
document.title = `Speedometer 3 ${sectionTitle}`.trimEnd();
358366
}
359367

360368
_removeLocationHash() {

0 commit comments

Comments
 (0)