-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathCustomSidebar.astro
More file actions
31 lines (27 loc) · 1.01 KB
/
CustomSidebar.astro
File metadata and controls
31 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---
import MobileMenuFooter from '@astrojs/starlight/components/MobileMenuFooter.astro';
import SidebarPersister from '@astrojs/starlight/components/SidebarPersister.astro';
import SidebarSublist from '@astrojs/starlight/components/SidebarSublist.astro';
const { sidebar } = Astro.locals.starlightRoute;
---
<script is:inline aria-hidden="true">
// This script scrolls the sidebar to the link matching the current page when the page loads
window.addEventListener('load', () => {
const sidebarContainer = document.getElementById('starlight__sidebar');
const currentItem = sidebarContainer.querySelector(
"a[aria-current='page']"
);
if (currentItem) {
sidebarContainer.scrollTo({
top: currentItem.offsetTop - sidebarContainer.offsetTop,
behavior: 'smooth',
});
}
});
</script>
<SidebarPersister>
<SidebarSublist sublist={sidebar} />
</SidebarPersister>
<div class="md:sl-hidden">
<MobileMenuFooter />
</div>