Skip to content

Commit 196cca6

Browse files
authored
Merge pull request #1455 from processing/underline-2
Implement persistent underline for top-level site section in left sid…
2 parents 938fb63 + cd3197f commit 196cca6

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎src/components/Nav/MainNavLinks.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type MainNavLinksProps = {
1515
hasJumpTo: boolean;
1616
handleToggle: () => void;
1717
isOpen: boolean;
18+
currentPath: string;
1819
};
1920

2021
export const MainNavLinks = ({
@@ -26,6 +27,7 @@ export const MainNavLinks = ({
2627
handleToggle,
2728
isOpen,
2829
hasJumpTo,
30+
currentPath,
2931
}: MainNavLinksProps) => {
3032
if (!links || links?.length <= 0) return null;
3133

@@ -75,8 +77,10 @@ export const MainNavLinks = ({
7577
{renderLogo()}
7678
<ul>
7779
{links.map((link) => (
78-
<li key={link.label}>
79-
<a href={link.url}>{link.label}</a>
80+
<li key={link.label} class={styles.linklabel}>
81+
<a href={link.url} class={currentPath === link.url ? "current" : ""}>
82+
{link.label}
83+
</a>
8084
</li>
8185
))}
8286
</ul>

‎src/components/Nav/NavPanels.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface NavPanelsProps {
1414
jumpToLabel: string;
1515
isHomepage: boolean;
1616
jumpToState: JumpToState | null;
17+
currentPath: string;
1718
}
1819

1920
/**
@@ -30,6 +31,7 @@ export const NavPanels = (props: NavPanelsProps) => {
3031
mobileMenuLabel,
3132
jumpToLabel,
3233
jumpToState,
34+
currentPath,
3335
} = props;
3436

3537
const [isOpen, setIsOpen] = useState({ main: false, jump: false });
@@ -90,6 +92,7 @@ export const NavPanels = (props: NavPanelsProps) => {
9092
hasJumpTo={jumpToState !== null}
9193
isOpen={isOpen.main}
9294
handleToggle={handleMainNavToggle}
95+
currentPath={currentPath}
9396
/>
9497
<JumpToLinks
9598
heading={jumpToState?.heading || jumpToLabel}

‎src/components/Nav/index.astro‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ const mainLinks = [
1919
{ url: "/about/", label: t("About") },
2020
] as { url: string; label: string }[];
2121
22+
// Define which paths should trigger an underline for a parent section
23+
const unmatchedPathMappings: Record<string, string> = {
24+
"/events/": "/community/",
25+
"/sketches/": "/community/",
26+
"/libraries/": "/community/",
27+
"/people/": "/about/",
28+
"/code-of-conduct/": "/about/",
29+
"/education-resources/": "/tutorials/",
30+
"/donate/": "/contribute/"
31+
};
32+
33+
// Check if the current URL matches the extra triggers
34+
const extraPathTriggers = Object.keys(unmatchedPathMappings).find(trigger =>
35+
pathMinusLocale.startsWith(trigger)
36+
);
37+
38+
// Set the active path: use the mapping if found, otherwise fall back to the main links logic
39+
const currentPath = extraPathTriggers
40+
? unmatchedPathMappings[extraPathTriggers]
41+
: (mainLinks.find((link) => pathMinusLocale.startsWith(link.url))?.url ?? "");
42+
2243
const editorButtonLabel = t("Start Coding");
2344
const donateButtonLabel = t("Donate");
2445
const mobileMenuLabel = t("Menu");
@@ -37,6 +58,7 @@ const jumpToLabel = t("Jump To");
3758
mobileMenuLabel={mobileMenuLabel as string}
3859
jumpToLabel={jumpToLabel as string}
3960
jumpToState={jumpToState}
61+
currentPath={currentPath}
4062
client:load
4163
/>
4264
</nav>

0 commit comments

Comments
 (0)