Skip to content

Commit 068ad6e

Browse files
author
Paul Richards
committed
Fix navigation paths for GitHub Pages subpath hosting
1 parent e529f67 commit 068ad6e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

shared/playground-header.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,27 @@
4343

4444
function getBasePath() {
4545
const path = window.location.pathname;
46-
if (path === '/' || path.endsWith('/index.html') && !path.includes('-')) {
46+
const pathParts = path.split('/').filter(Boolean);
47+
48+
if (pathParts.length === 0) {
4749
return './';
4850
}
49-
return '../';
51+
52+
const lastPart = pathParts[pathParts.length - 1];
53+
const secondLastPart = pathParts[pathParts.length - 2] || '';
54+
55+
if (lastPart === 'index.html') {
56+
if (secondLastPart.match(/^\d{2}-/) || secondLastPart === 'PTZOptics-Moondream-Tracker') {
57+
return '../';
58+
}
59+
return './';
60+
}
61+
62+
if (lastPart.match(/^\d{2}-/) || lastPart === 'PTZOptics-Moondream-Tracker') {
63+
return '../';
64+
}
65+
66+
return './';
5067
}
5168

5269
function injectStyles() {

0 commit comments

Comments
 (0)