Skip to content

Commit 081e848

Browse files
committed
fix: Page titles
1 parent 81babc8 commit 081e848

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/lib/page-title.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ export function createTitle(title) {
77
// Titles for various content areas
88
let suffix = '';
99
switch (true) {
10-
// Shouldn't be an issue, but `startsWith` is wildly faster than `includes`
1110
case url.startsWith('/guide/v11'):
12-
case url.startsWith('/guide/v10'):
1311
suffix = 'Preact Guide';
1412
break;
15-
case url.startsWith('/tutorial'):
16-
suffix = 'Preact Tutorial';
13+
case url.startsWith('/guide/v10'):
14+
suffix = 'Preact Guide v10';
1715
break;
1816
case url.startsWith('/guide/v8'):
19-
suffix = 'Preact Version 8';
17+
suffix = 'Preact Guide v8';
18+
break;
19+
case url.startsWith('/tutorial'):
20+
suffix = 'Preact Tutorial';
2021
break;
2122
default:
2223
suffix = 'Preact';

src/lib/use-content.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect } from 'preact/hooks';
2+
import { useLocation } from 'preact-iso';
23

34
import { createTitle } from './page-title';
45
import { getContent } from './content.js';
@@ -59,14 +60,17 @@ export function prefetchContent(path) {
5960
* @param {string} title
6061
*/
6162
export function useTitle(title) {
63+
const { url } = useLocation();
64+
6265
if (typeof window === 'undefined') {
6366
globalThis.title = createTitle(title);
6467
}
68+
6569
useEffect(() => {
6670
if (title) {
6771
document.title = createTitle(title);
6872
}
69-
}, [title]);
73+
}, [title, url]);
7074
}
7175

7276
/**

0 commit comments

Comments
 (0)