Fix tab highlight: exact category URL match instead of substring

/categories/dark-fantasy/ was also activating the Fantasy tab
because path.includes('fantasy') matched. Now compares the full
/categories/{slug}/ path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-18 17:33:42 +02:00
parent 073c4b804c
commit e8226b2e2f
2 changed files with 6 additions and 4 deletions
+3 -2
View File
@@ -91,8 +91,9 @@
const path = location.pathname;
tabs.forEach(btn => {
const cat = btn.dataset.cat;
const active = (cat === 'All' && (path === '/' || path.startsWith('/issue') || path === '/posts/'))
|| (cat !== 'All' && path.toLowerCase().includes(cat.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '')));
const slug = cat.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
const active = (cat === 'All' && (path === '/' || path.startsWith('/issues') || path === '/posts/'))
|| (cat !== 'All' && path === `/categories/${slug}/`);
btn.setAttribute('aria-pressed', active ? 'true' : 'false');
});
}