Skip to content

Commit f66c1ca

Browse files
committed
Expand details section when navigated directly via the URL hash
1 parent 8679fa7 commit f66c1ca

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/layouts/Base.astro

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,5 +374,21 @@ const ogImage = lockdownImages.length > 0
374374
</head>
375375
<body>
376376
<slot />
377+
<script is:inline>
378+
function openDetailsForHash() {
379+
var hash = location.hash;
380+
if (!hash) return;
381+
var target = document.querySelector(hash);
382+
if (!target) return;
383+
var el = target;
384+
while (el) {
385+
if (el.tagName === 'DETAILS') el.open = true;
386+
el = el.parentElement;
387+
}
388+
target.scrollIntoView();
389+
}
390+
openDetailsForHash();
391+
window.addEventListener('hashchange', openDetailsForHash);
392+
</script>
377393
</body>
378394
</html>

0 commit comments

Comments
 (0)