Skip to content

Commit 76f1714

Browse files
authored
Merge pull request #61 from devwqc/fix/home-blog
[fix] Home, Blog 페이지 통일
2 parents b3a155d + 600f19c commit 76f1714

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

src/components/HeaderLink.astro

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
---
22
import type { HTMLAttributes } from 'astro/types';
33
4-
type Props = HTMLAttributes<'a'>;
4+
type Props = HTMLAttributes<'a'> & {
5+
incldues: string[];
6+
};
57
6-
const { href, class: className, ...props } = Astro.props;
8+
const { href, incldues, class: className, ...props } = Astro.props;
79
810
const { pathname } = Astro.url;
911
const subpath = pathname.match(/[^\/]+/g);
10-
const isActive = href === pathname || href === '/' + subpath?.[0];
12+
const isActive = incldues.find((path) => {
13+
return path === pathname || path === '/' + subpath?.[0];
14+
});
1115
---
1216

1317
<a

src/components/Navigation.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { menu } from '@/constants/menu';
77
{
88
menu.map((item) => (
99
<li>
10-
<HeaderLink href={item.path}>{item.label}</HeaderLink>
10+
<HeaderLink href={item.path} incldues={item.includes}>
11+
{item.label}
12+
</HeaderLink>
1113
</li>
1214
))
1315
}

src/components/NavigationMobile.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import HamburgerSvg from './HamburgerSvg.astro';
1212
{
1313
menu.map((item) => (
1414
<li>
15-
<HeaderLink href={item.path} class="block">
15+
<HeaderLink href={item.path} incldues={item.includes} class="block">
1616
{item.label}
1717
</HeaderLink>
1818
</li>

src/constants/menu.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
export const menu = [
1+
export const menu: {
2+
path: string;
3+
label: string;
4+
includes: string[];
5+
}[] = [
26
{
37
path: '/blog',
48
label: 'Blog',
9+
includes: ['/', '/blog'],
510
},
611
{
712
path: '/about',
813
label: 'About',
14+
includes: ['/about'],
915
},
1016
];

src/pages/index.astro

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
11
---
2+
import FormattedDate from '@/components/FormattedDate.astro';
23
import PageLayout from '@/layouts/PageLayout.astro';
4+
import { getCollection } from 'astro:content';
35
4-
return Astro.redirect('/blog');
6+
const posts = (await getCollection('blog')).sort(
7+
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
8+
);
59
---
610

7-
<PageLayout title="Home" />
11+
<PageLayout title="Home">
12+
<ul>
13+
{
14+
posts.map((post) => (
15+
<li class="py-5">
16+
<article>
17+
<a
18+
href={`/blog/${post.slug}/`}
19+
class="hover:text-emerald-600 flex flex-col gap-1"
20+
>
21+
<h2 class="text-3xl font-bold">{post.data.title}</h2>
22+
<p class="text-gray-500 text-sm">
23+
<span>
24+
작성일:
25+
<FormattedDate datetime={post.data.pubDate} />
26+
</span>
27+
{post.data.updatedDate && (
28+
<span>
29+
수정일:
30+
<FormattedDate datetime={post.data.updatedDate} />
31+
</span>
32+
)}
33+
</p>
34+
<p class="text-slate-500">{post.data.description}</p>
35+
</a>
36+
</article>
37+
</li>
38+
))
39+
}
40+
</ul>
41+
</PageLayout>

0 commit comments

Comments
 (0)