Skip to content

Commit 6b1bbd9

Browse files
Redirect to root when starting demo (#3323)
* Redirect to root when starting demo * Update package.json * Update index.astro * Update index.astro
1 parent 6ad2839 commit 6b1bbd9

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

docs-src/src/content/docs/guides/install.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ with:
5050
```html
5151
<script
5252
type="module"
53-
src="https://cdn.jsdelivr.net/npm/shepherd.js@15.0.0/dist/js/shepherd.mjs"
53+
src="https://cdn.jsdelivr.net/npm/shepherd.js@17.0.0/dist/js/shepherd.mjs"
5454
></script>
5555
<link
5656
rel="stylesheet"
57-
href="https://cdn.jsdelivr.net/npm/shepherd.js@15.0.0/dist/css/shepherd.css"
57+
href="https://cdn.jsdelivr.net/npm/shepherd.js@17.0.0/dist/css/shepherd.css"
5858
/>
5959
```
6060

landing/src/components/Header.astro

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,34 @@ const { isHome } = Astro.props;
162162
}
163163
</div>
164164
</header>
165+
166+
<script>
167+
// Handle demo button click - redirect to home if not already there
168+
function setupDemoButton() {
169+
const showTourBtn = document.querySelector('#showTour');
170+
171+
if (!showTourBtn) return;
172+
173+
// Remove any existing listeners
174+
const newBtn = showTourBtn.cloneNode(true) as HTMLElement;
175+
showTourBtn.parentNode?.replaceChild(newBtn, showTourBtn);
176+
177+
newBtn.addEventListener('click', () => {
178+
// Check if we're on the home page
179+
if (window.location.pathname !== '/') {
180+
// Store flag to start tour after navigation
181+
sessionStorage.setItem('startTourOnLoad', 'true');
182+
window.location.href = '/';
183+
} else {
184+
// We're already on home page, dispatch event to start tour
185+
window.dispatchEvent(new CustomEvent('startTour'));
186+
}
187+
});
188+
}
189+
190+
// Run on initial load
191+
document.addEventListener('DOMContentLoaded', setupDemoButton);
192+
193+
// Run on Astro page transitions
194+
document.addEventListener('astro:page-load', setupDemoButton);
195+
</script>

landing/src/pages/index.astro

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import MainPage from '@layouts/MainPage.astro';
2424
<Code
2525
code={`
2626
<link rel="stylesheet" href="shepherd.js/dist/css/shepherd.css"/>
27-
<script type="module" src="shepherd.js/dist/shepherd.mjs"></script>
27+
<script type="module" src="shepherd.js/dist/js/shepherd.mjs"></script>
2828
2929
`}
3030
lang="js"
@@ -94,9 +94,25 @@ import MainPage from '@layouts/MainPage.astro';
9494
// wait for shepherd to be ready
9595
setTimeout(function () {
9696
const shepherd = setupShepherd();
97-
const startBtn = document.querySelector('#showTour');
98-
99-
startBtn?.addEventListener('click', () => shepherd.start());
97+
98+
// Check if we should auto-start the tour (after redirect from another page)
99+
const shouldStartTour = sessionStorage.getItem('startTourOnLoad');
100+
if (shouldStartTour) {
101+
sessionStorage.removeItem('startTourOnLoad');
102+
shepherd.start();
103+
}
104+
105+
// Clean up previous listener if it exists
106+
if ((window as any).__startTourAbortController) {
107+
(window as any).__startTourAbortController.abort();
108+
}
109+
110+
// Create new AbortController for this listener
111+
const controller = new AbortController();
112+
(window as any).__startTourAbortController = controller;
113+
114+
// Listen for custom event from Demo button when already on home page
115+
window.addEventListener('startTour', () => shepherd.start(), { signal: controller.signal });
100116
}, 400);
101117
}
102118

@@ -296,7 +312,8 @@ import MainPage from '@layouts/MainPage.astro';
296312
}
297313

298314
function ready() {
299-
document.addEventListener('DOMContentLoaded', init);
315+
// Only listen for astro:page-load which fires on both initial load and transitions
316+
document.addEventListener('astro:page-load', init);
300317
}
301318

302319
ready();

shepherd.js/dummy/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ <h3>Example</h3>
122122

123123
<!-- Shepherd -->
124124
<script type="module">
125-
import Shepherd from '../dist/esm/shepherd.mjs';
125+
import Shepherd from '../dist/js/shepherd.mjs';
126126

127127
window.Shepherd = Shepherd;
128128

shepherd.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"Robbie Wagner <[email protected]>",
1919
"Chuck Carpenter <[email protected]>"
2020
],
21-
"main": "./dist/cjs/shepherd.cjs",
21+
"main": "./dist/js/shepherd.mjs",
2222
"module": "./dist/js/shepherd.mjs",
2323
"exports": {
2424
".": {

0 commit comments

Comments
 (0)