Skip to content

Commit e423450

Browse files
committed
Don't rely on Astro.url
1 parent 2781c8d commit e423450

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

src/components/header/tablet/Menu.astro

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@ import { PAGES, SOCIAL_MEDIA_LINKS } from "../../../consts";
33
import HeaderLink from "../HeaderLink.astro";
44
import MenuItem from "./MenuItem.astro";
55
import ThemeDropdown from "./ThemeDropdown.astro";
6+
7+
interface Props {
8+
/**
9+
* The title of the current page
10+
*/
11+
title: string;
12+
/**
13+
* Whether the current page is a blog post
14+
*/
15+
isBlogPost: boolean;
16+
}
17+
18+
const { title, isBlogPost } = Astro.props;
619
---
720

821
<div id="laptop-header" class="header">
922
<nav class="menu">
10-
{PAGES.map((page) => <MenuItem {...page} />)}
23+
{PAGES.map((page) => <MenuItem curr={title} isBlogPost={isBlogPost} {...page} />)}
1124
</nav>
1225
<div class="text-start social-media-icons">
1326
{

src/components/header/tablet/MenuItem.astro

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@
44
import HeaderLink from "../HeaderLink.astro";
55
66
interface Props {
7+
/**
8+
* The title of the current page
9+
*/
10+
curr: string;
11+
/**
12+
* Whether the current page is a blog post
13+
*/
14+
isBlogPost: boolean;
715
link: string;
816
name: string;
917
leetName: string;
1018
}
1119
12-
const { link, name, leetName } = Astro.props;
20+
const { curr, isBlogPost, link, name, leetName } = Astro.props;
21+
const selected = curr === name || (isBlogPost && name === "Blog");
1322
---
1423

1524
<HeaderLink link={link} title={name}>
16-
<span class="item" class:list={[{ selected: Astro.url.pathname == link }]}>
25+
<span class="item" class:list={[{ selected }]}>
1726
{leetName}
1827
</span>
1928
</HeaderLink>

src/layouts/BaseLayout.astro

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import HomeLink from "../components/header/HomeLink.astro";
55
import TabletHeader from "../components/header/tablet/Menu.astro";
66
import MobileHeader from "../components/header/mobile/Menu.astro";
77
8-
const { frontmatter } = Astro.props;
8+
interface Props {
9+
frontmatter?: { title: string };
10+
title: string;
11+
isBlogPost: boolean;
12+
}
13+
14+
const { frontmatter, isBlogPost } = Astro.props;
915
let { title } = Astro.props;
1016
// If a title wasn't explicitly passed in, get it from the frontmatter
1117
if (!title && frontmatter && "title" in frontmatter) {
@@ -23,7 +29,7 @@ if (!title && frontmatter && "title" in frontmatter) {
2329
<header>
2430
<HomeLink />
2531
<MobileHeader />
26-
<TabletHeader />
32+
<TabletHeader title={title} isBlogPost={isBlogPost} />
2733
</header>
2834
<main>
2935
<slot />

src/layouts/BlogPost.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { title, description, author, pubDate, updatedDate, heroImage } =
99
Astro.props;
1010
---
1111

12-
<BaseLayout title={title} description={description}>
12+
<BaseLayout title={title} isBlogPost={true} description={description}>
1313
<article>
1414
<div class="hero-image">
1515
{heroImage && <img width={1020} height={510} src={heroImage} alt="" />}

0 commit comments

Comments
 (0)