{title}
--
From d377b3d739c44339432c37fee7167b8ff1b4a8da Mon Sep 17 00:00:00 2001
From: Blboun3 <62328614+Blboun3@users.noreply.github.com>
Date: Thu, 30 May 2024 13:27:24 +0200
Subject: [PATCH] Fixed navbar current page in blog posts
When in blog post the current page on navbar is highlighting now blog (previously was none, since url != /blog nor /)
---
src/components/Navbar.astro | 10 ++++++---
src/layouts/BlogPost.astro | 21 +++++-------------
src/pages/[lang]/blog/[...slug].astro | 32 +++++++++++++++------------
3 files changed, 30 insertions(+), 33 deletions(-)
diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro
index eed4180..2cc0c3e 100644
--- a/src/components/Navbar.astro
+++ b/src/components/Navbar.astro
@@ -6,10 +6,14 @@ import { LangSwitcher } from "./LangSwitcher";
import { NavButton } from "./NavButton";
function selected(path) {
- return (
- (Astro.url.pathname
+ var currentURL = Astro.url.pathname
.replace(Astro.currentLocale + "/", "")
- .slice(0, -1) || "/") == path
+ .slice(0, -1) || "/";
+ if( path == "/blog" && currentURL.startsWith("/blog") ){
+ return (true);
+ }
+ return (
+ currentURL == path
);
}
---
diff --git a/src/layouts/BlogPost.astro b/src/layouts/BlogPost.astro
index 6900fa5..727d367 100644
--- a/src/layouts/BlogPost.astro
+++ b/src/layouts/BlogPost.astro
@@ -6,26 +6,15 @@ import MainLayout from "./MainLayout.astro";
type Props = CollectionEntry<"blog">["data"];
-const { title, description, publishDate, language } =
- Astro.props;
+const { title, description, language } = Astro.props;
---
by {page.data.author} • {formattedDate}{title}
-
- {page.data.title}
-
{page.data.author} • {formattedDate}
+