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'], }, ]; 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() +); --- - + +
    +