@@ -1339,7 +1339,7 @@ function getMermaidScriptEntry() {
13391339 return txt.value;
13401340 }
13411341
1342- // wenn Reveal „ready“ ist, oder einfach bei DOMContentLoaded
1342+ // If reveal is ready, or simply on DOMContentLoaded
13431343 document.addEventListener("DOMContentLoaded", () => {
13441344 document.querySelectorAll("pre.mermaid").forEach(async (el, i) => {
13451345 const raw = el.textContent;
@@ -1355,6 +1355,51 @@ function getMermaidScriptEntry() {
13551355</script>` ;
13561356}
13571357
1358+ function getAutoReloadScript ( ) {
1359+ return `<script>
1360+ (function() {
1361+ let scrollY = 0;
1362+ let slideIndices = null;
1363+ const es = new EventSource('/hot-reload');
1364+ es.addEventListener('reload', function() {
1365+ if (window.Reveal && Reveal.getIndices) {
1366+ slideIndices = Reveal.getIndices();
1367+ sessionStorage.setItem("revealSlide", JSON.stringify(slideIndices));
1368+ } else {
1369+ scrollY = window.scrollY;
1370+ sessionStorage.setItem("scrollY", scrollY);
1371+ }
1372+ location.reload();
1373+ });
1374+
1375+ window.addEventListener("DOMContentLoaded", function() {
1376+ // Hide body until slide/scroll is restored
1377+ document.body.style.display = "none";
1378+ if (window.Reveal && Reveal.slide) {
1379+ const saved = sessionStorage.getItem("revealSlide");
1380+ if (saved) {
1381+ const idx = JSON.parse(saved);
1382+ Reveal.slide(idx.h, idx.v || 0);
1383+ sessionStorage.removeItem("revealSlide");
1384+ setTimeout(function() {
1385+ document.body.style.display = "";
1386+ }, 0); // Reveal.slide is synchronous, but just in case
1387+ } else {
1388+ document.body.style.display = "";
1389+ }
1390+ } else {
1391+ const savedY = sessionStorage.getItem("scrollY");
1392+ if (savedY) {
1393+ window.scrollTo(0, parseInt(savedY, 10));
1394+ sessionStorage.removeItem("scrollY");
1395+ }
1396+ document.body.style.display = "";
1397+ }
1398+ });
1399+ })();
1400+ </script>`
1401+ }
1402+
13581403export async function wrapInPage ( html , startPage , req ) {
13591404 const pre = `
13601405 <!DOCTYPE html>
@@ -1385,6 +1430,7 @@ export async function wrapInPage(html, startPage, req) {
13851430 </div>
13861431 <script src="/obsidian-page.js"></script>
13871432 ${ getMermaidScriptEntry ( ) }
1433+ ${ getAutoReloadScript ( ) }
13881434 <script lang="javascript">
13891435 initFonts('${ JSON . stringify ( mainFontsArray ) } ', '${ JSON . stringify (
13901436 navFontsArray
@@ -1420,6 +1466,7 @@ export async function wrapAsDocument(html, req) {
14201466 </div>
14211467 <script src="/obsidian-page.js"></script>
14221468 ${ getMermaidScriptEntry ( ) }
1469+ ${ getAutoReloadScript ( ) }
14231470 <script lang="javascript">
14241471 initFonts('${ JSON . stringify ( mainFontsArray ) } ', '${ JSON . stringify (
14251472 navFontsArray
@@ -1503,6 +1550,7 @@ export async function wrapInReveal(reveal, req) {
15031550 <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/tomorrow.min.css"> -->
15041551
15051552 ${ getMermaidScriptEntry ( ) }
1553+ ${ getAutoReloadScript ( ) }
15061554
15071555 <!-- Printing and PDF exports -->
15081556 <script>
0 commit comments