Skip to content

Commit

Permalink
Merge pull request #62 from devwqc/develop
Browse files Browse the repository at this point in the history
[release] develop to main
  • Loading branch information
devwqc authored Nov 8, 2024
2 parents ea3cf80 + 76f1714 commit 9c21697
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/components/HeaderLink.astro
Original file line number Diff line number Diff line change
@@ -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];
});
---

<a
Expand Down
4 changes: 3 additions & 1 deletion src/components/Navigation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { menu } from '@/constants/menu';
{
menu.map((item) => (
<li>
<HeaderLink href={item.path}>{item.label}</HeaderLink>
<HeaderLink href={item.path} incldues={item.includes}>
{item.label}
</HeaderLink>
</li>
))
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/NavigationMobile.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import HamburgerSvg from './HamburgerSvg.astro';
{
menu.map((item) => (
<li>
<HeaderLink href={item.path} class="block">
<HeaderLink href={item.path} incldues={item.includes} class="block">
{item.label}
</HeaderLink>
</li>
Expand Down
8 changes: 7 additions & 1 deletion src/constants/menu.ts
Original file line number Diff line number Diff line change
@@ -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'],
},
];
38 changes: 36 additions & 2 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -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()
);
---

<PageLayout title="Home" />
<PageLayout title="Home">
<ul>
{
posts.map((post) => (
<li class="py-5">
<article>
<a
href={`/blog/${post.slug}/`}
class="hover:text-emerald-600 flex flex-col gap-1"
>
<h2 class="text-3xl font-bold">{post.data.title}</h2>
<p class="text-gray-500 text-sm">
<span>
작성일:
<FormattedDate datetime={post.data.pubDate} />
</span>
{post.data.updatedDate && (
<span>
수정일:
<FormattedDate datetime={post.data.updatedDate} />
</span>
)}
</p>
<p class="text-slate-500">{post.data.description}</p>
</a>
</article>
</li>
))
}
</ul>
</PageLayout>

0 comments on commit 9c21697

Please sign in to comment.