Skip to content

Commit 8d21101

Browse files
committed
Different fixes and improvements
1 parent 000567c commit 8d21101

2 files changed

Lines changed: 37 additions & 19 deletions

File tree

src/components/Sidebar.astro

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ function transformItems(items: any[]): any[] {
5151
}
5252
}
5353
54-
// Handle category with link but no label
55-
if (item.type === 'category' && item.link?.id && (!item.label || item.label.trim() === '')) {
56-
const title = docTitles.get(item.link.id);
57-
if (title) {
58-
newItem.label = title;
54+
// Handle category with link but no label (either link.id or direct id)
55+
if (item.type === 'category' && (!item.label || item.label.trim() === '')) {
56+
const linkId = item.link?.id || item.id;
57+
if (linkId) {
58+
const title = docTitles.get(linkId);
59+
if (title) {
60+
newItem.label = title;
61+
}
5962
}
6063
}
6164
@@ -79,10 +82,13 @@ function transformItems(items: any[]): any[] {
7982
newItem.href = newItem.href.replace(/\/+/g, '/');
8083
}
8184
82-
// Handle category with link
83-
if (item.type === 'category' && item.link?.id && !item.href) {
84-
const customSlug = docSlugs.get(item.link.id);
85-
newItem.href = `${import.meta.env.BASE_URL}${customSlug || `/${item.link.id}`}`.replace(/\/+/g, '/');
85+
// Handle category with link (either link.id or direct id)
86+
if (item.type === 'category' && !item.href) {
87+
const linkId = item.link?.id || item.id;
88+
if (linkId) {
89+
const customSlug = docSlugs.get(linkId);
90+
newItem.href = `${import.meta.env.BASE_URL}${customSlug || `/${linkId}`}`.replace(/\/+/g, '/');
91+
}
8692
}
8793
if (item.items) {
8894
newItem.items = transformItems(item.items);

src/components/SidebarItem.astro

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ const textColor = getTextColor(depth, isActive);
141141

142142
<style>
143143
:global(.sidebar-item-active),
144-
:global(.sidebar-item-active:visited) {
144+
:global(.sidebar-item-active:visited),
145+
:global(.sidebar-item-active) .category-title-link,
146+
:global(.sidebar-item-active) .category-title-link:visited {
145147
color: var(--text-primary) !important;
146148
/* Removed font-weight change to prevent layout shift/wrapping */
147149
}
@@ -167,6 +169,10 @@ const textColor = getTextColor(depth, isActive);
167169
color: var(--text-primary) !important;
168170
}
169171

172+
:global(.sidebar-item-hover:hover) .category-title-link {
173+
color: var(--text-primary) !important;
174+
}
175+
170176
/* Removed .sidebar-indicator styles as it's no longer used */
171177

172178
:global(.sidebar-toggle-btn:hover) {
@@ -241,11 +247,13 @@ const textColor = getTextColor(depth, isActive);
241247
});
242248
});
243249

250+
// Handle category title clicks
244251
titleLinks.forEach(link => {
245-
// Check if listener already exists
246252
if (link.hasAttribute('data-listener-added')) return;
247253
link.setAttribute('data-listener-added', 'true');
248254

255+
const isNavLink = link.tagName === 'A';
256+
249257
link.addEventListener('click', (e) => {
250258
const categoryId = link.getAttribute('data-category-id');
251259
const itemsList = document.querySelector(`.category-items-container[data-category-id="${categoryId}"]`);
@@ -255,17 +263,21 @@ const textColor = getTextColor(depth, isActive);
255263
if (!itemsList || !svg) return;
256264

257265
const isCurrentlyExpanded = itemsList.classList.contains('expanded');
258-
const isNavLink = link.tagName === 'A';
259266

260-
// For non-nav links (buttons), toggle the category
261-
if (!isNavLink) {
267+
// For navigation links: always expand if collapsed, then let navigation happen
268+
if (isNavLink) {
269+
if (!isCurrentlyExpanded) {
270+
// Expand the category (don't prevent default - let navigation happen)
271+
itemsList.classList.add('expanded');
272+
svg.style.transform = 'rotate(90deg)';
273+
}
274+
// Always allow navigation
275+
}
276+
// For buttons: always toggle
277+
else {
278+
e.preventDefault();
262279
itemsList.classList.toggle('expanded');
263280
svg.style.transform = isCurrentlyExpanded ? 'rotate(0deg)' : 'rotate(90deg)';
264-
}
265-
// For nav links, expand if collapsed (but don't collapse if expanded - let navigation happen)
266-
else if (!isCurrentlyExpanded) {
267-
itemsList.classList.add('expanded');
268-
svg.style.transform = 'rotate(90deg)';
269281
}
270282
});
271283
});

0 commit comments

Comments
 (0)