@@ -83,6 +83,7 @@ const currentSlug = pathParts[pathParts.length - 1];
8383<script is:inline >
8484 (function() {
8585 const SCROLL_KEY = 'sidebar-scroll';
86+ const CATEGORY_KEY = 'sidebar-category';
8687
8788 function closeMobileMenu() {
8889 const sidebar = document.getElementById('sidebar');
@@ -101,18 +102,30 @@ const currentSlug = pathParts[pathParts.length - 1];
101102 return document.querySelector('#sidebar > div');
102103 }
103104
105+ function getCurrentCategory() {
106+ // Extract category from URL pattern: /docs/{category}/{slug}
107+ const match = window.location.pathname.match(/\/docs\/([^/]+)\//);
108+ return match ? match[1] : null;
109+ }
110+
104111 function saveScrollPosition() {
105112 const container = getScrollContainer();
106- if (container) {
113+ const category = getCurrentCategory();
114+ if (container && category) {
107115 sessionStorage.setItem(SCROLL_KEY, container.scrollTop.toString());
116+ sessionStorage.setItem(CATEGORY_KEY, category);
108117 }
109118 }
110119
111120 function restoreScrollPosition() {
112121 const container = getScrollContainer();
113- const saved = sessionStorage.getItem(SCROLL_KEY);
114- if (container && saved) {
115- container.scrollTop = parseInt(saved, 10);
122+ const savedScroll = sessionStorage.getItem(SCROLL_KEY);
123+ const savedCategory = sessionStorage.getItem(CATEGORY_KEY);
124+ const currentCategory = getCurrentCategory();
125+
126+ // Only restore scroll if staying in the same category
127+ if (container && savedScroll && savedCategory === currentCategory) {
128+ container.scrollTop = parseInt(savedScroll, 10);
116129 }
117130 }
118131
0 commit comments