@@ -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();
0 commit comments