From fc49aca008c581f57aa0ba2c74ebf6ebb90ba976 Mon Sep 17 00:00:00 2001 From: devwqc Date: Fri, 8 Nov 2024 14:40:07 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20menu=EC=97=90=20includes?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EB=A1=9C=20/=20=EA=B2=BD=EB=A1=9C=EB=8F=84?= =?UTF-8?q?=20header=EC=97=90=20Blog=20active?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/HeaderLink.astro | 10 +++++++--- src/components/Navigation.astro | 4 +++- src/components/NavigationMobile.astro | 2 +- src/constants/menu.ts | 8 +++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/HeaderLink.astro b/src/components/HeaderLink.astro index 55faee2..45998a6 100644 --- a/src/components/HeaderLink.astro +++ b/src/components/HeaderLink.astro @@ -1,13 +1,17 @@ --- import type { HTMLAttributes } from 'astro/types'; -type Props = HTMLAttributes<'a'>; +type Props = HTMLAttributes<'a'> & { + incldues: string[]; +}; -const { href, class: className, ...props } = Astro.props; +const { href, incldues, class: className, ...props } = Astro.props; const { pathname } = Astro.url; const subpath = pathname.match(/[^\/]+/g); -const isActive = href === pathname || href === '/' + subpath?.[0]; +const isActive = incldues.find((path) => { + return path === pathname || path === '/' + subpath?.[0]; +}); --- (
  • - {item.label} + + {item.label} +
  • )) } diff --git a/src/components/NavigationMobile.astro b/src/components/NavigationMobile.astro index 5ebeccc..42a4f10 100644 --- a/src/components/NavigationMobile.astro +++ b/src/components/NavigationMobile.astro @@ -12,7 +12,7 @@ import HamburgerSvg from './HamburgerSvg.astro'; { menu.map((item) => (
  • - + {item.label}
  • diff --git a/src/constants/menu.ts b/src/constants/menu.ts index 33a6ffa..aac63b8 100644 --- a/src/constants/menu.ts +++ b/src/constants/menu.ts @@ -1,10 +1,16 @@ -export const menu = [ +export const menu: { + path: string; + label: string; + includes: string[]; +}[] = [ { path: '/blog', label: 'Blog', + includes: ['/', '/blog'], }, { path: '/about', label: 'About', + includes: ['/about'], }, ]; From 600f19c23ef3f5e60784cd44be8e8943ba489635 Mon Sep 17 00:00:00 2001 From: devwqc Date: Fri, 8 Nov 2024 14:40:34 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20HomePage=20=EB=82=B4=EC=9A=A9?= =?UTF-8?q?=20BlogListPage=EC=99=80=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index.astro | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index aea2841..9d08d11 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,7 +1,41 @@ --- +import FormattedDate from '@/components/FormattedDate.astro'; import PageLayout from '@/layouts/PageLayout.astro'; +import { getCollection } from 'astro:content'; -return Astro.redirect('/blog'); +const posts = (await getCollection('blog')).sort( + (a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf() +); --- - + +
    +