Skip to content

Commit 4441e44

Browse files
committed
fix : 이전포스트, 다음포스트 수정
1 parent e845823 commit 4441e44

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

content/blog/to-do/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ tags: ["블로그", "기능"]
1010

1111
이제 기본적인 블로그의 틀은 완성된거같구요.
1212

13-
이제 다음으로 우선적으로 구현할 기능은 아마 목차와 댓글 기능 정도가 되겠군여.
13+
버그들이 좀 있는것같으니 버그들부터 빨리 수정하고,,
14+
15+
다음으로 우선적으로 구현할 기능은 아마 목차와 댓글 기능 정도가 되겠군여.
1416

1517
Cursor에 의지해서 너무 쉽게 여러가지 기능들을 구현하긴했는데, Gatsby에 대한 이해도를 높힐 겸 직접 이해하면서 구현해봐야겠어요.
1618

gatsby-node.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ exports.createPages = async ({
5555
// 1. 개별 블로그 포스트 페이지 생성
5656
if (posts.length > 0) {
5757
posts.forEach((post: any, index: number) => {
58+
// posts는 최신순 정렬 (DESC)
59+
// previous: 시간상 이전 포스트 (더 오래된 포스트) = index + 1
60+
// next: 시간상 다음 포스트 (더 최신 포스트) = index - 1
5861
const previousPostId =
5962
index === posts.length - 1 ? null : posts[index + 1].id
6063
const nextPostId = index === 0 ? null : posts[index - 1].id

src/templates/blog-post.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,8 @@ const BlogPostTemplate: React.FC<BlogPostTemplateProps> = ({
118118
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
119119
{/* 이전 포스트 */}
120120
<div className="md:justify-self-start">
121-
{previous && (
122-
<Link
123-
to={previous.fields.slug}
124-
rel="prev"
125-
className="group block"
126-
>
121+
{next && (
122+
<Link to={next.fields.slug} rel="prev" className="group block">
127123
<div className="bg-card hover:bg-card/80 border rounded-lg p-6 transition-colors duration-200">
128124
<div className="flex items-start space-x-3">
129125
<div className="flex-shrink-0 p-2 bg-muted rounded-full group-hover:bg-muted/80 transition-colors">
@@ -134,7 +130,7 @@ const BlogPostTemplate: React.FC<BlogPostTemplateProps> = ({
134130
이전 포스트
135131
</p>
136132
<h3 className="font-semibold text-foreground group-hover:text-primary transition-colors line-clamp-2">
137-
{previous.frontmatter.title}
133+
{next.frontmatter.title}
138134
</h3>
139135
</div>
140136
</div>
@@ -145,16 +141,20 @@ const BlogPostTemplate: React.FC<BlogPostTemplateProps> = ({
145141

146142
{/* 다음 포스트 */}
147143
<div className="md:justify-self-end">
148-
{next && (
149-
<Link to={next.fields.slug} rel="next" className="group block">
144+
{previous && (
145+
<Link
146+
to={previous.fields.slug}
147+
rel="next"
148+
className="group block"
149+
>
150150
<div className="bg-card hover:bg-card/80 border rounded-lg p-6 transition-colors duration-200">
151151
<div className="flex items-start space-x-3">
152152
<div className="flex-1 min-w-0 text-right">
153153
<p className="text-sm text-muted-foreground mb-1">
154154
다음 포스트
155155
</p>
156156
<h3 className="font-semibold text-foreground group-hover:text-primary transition-colors line-clamp-2">
157-
{next.frontmatter.title}
157+
{previous.frontmatter.title}
158158
</h3>
159159
</div>
160160
<div className="flex-shrink-0 p-2 bg-muted rounded-full group-hover:bg-muted/80 transition-colors">

0 commit comments

Comments
 (0)