Skip to content

Commit

Permalink
Patched colouring in TreeNav
Browse files Browse the repository at this point in the history
  • Loading branch information
jdjfisher committed Dec 2, 2024
1 parent 7469ac2 commit 899020c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/TreeNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function InternalNode({
currentPath: string;
depth: number;
}) {
const relatesToCurrentPath = currentPath.includes(node.path);
const relatesToCurrentPath = currentPath.startsWith(node.path);

const [expanded, setExpanded] = useState(relatesToCurrentPath);

Expand Down
5 changes: 3 additions & 2 deletions src/components/layout/NavLink.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ interface Props {
const { href } = Astro.props;
const currentPath = Astro.url.pathname;
// Remove trailing slash
const currentPath = Astro.url.pathname.replace(/\/$/, '');
const active = currentPath.includes(href);
const active = currentPath.endsWith(href);
---

<li
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/GuideLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import TreeNav from '@/components/TreeNav';
import type { TreeNavNode } from '@/types';
import RootLayout from './RootLayout.astro';
const currentPath = Astro.url.pathname;
// Remove trailing slash
const currentPath = Astro.url.pathname.replace(/\/$/, '');
const rootNode: TreeNavNode = {
name: 'Guides',
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/ModuleLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import modules from '@/assets/modules.json';
import { moduleCategoryToNode } from '@/lib/modules';
import RootLayout from '@/layouts/RootLayout.astro';
const currentPath = Astro.url.pathname;
// Remove trailing slash
const currentPath = Astro.url.pathname.replace(/\/$/, '');
const rootNode = moduleCategoryToNode(modules);
---
Expand Down

0 comments on commit 899020c

Please sign in to comment.