Skip to content

Commit 17cf285

Browse files
Yushin-Lclaude
andcommitted
Show author name and timestamp on post list and detail pages
- Join profiles table to fetch author display_name for Supabase posts - Display author name and ko-KR formatted timestamp in DynamicPostView (detail) - Map author_name in SupabasePostsWithFilter (list) PostCard Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9becd05 commit 17cf285

4 files changed

Lines changed: 43 additions & 9 deletions

File tree

src/components/posts/DynamicPostView.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ export default function DynamicPostView({ slug }: DynamicPostViewProps) {
5454
</h1>
5555
<div className="mt-4 flex flex-wrap items-center gap-3">
5656
<span className="text-sm text-stone-500">
57-
{post.created_at.split("T")[0]}
57+
{post.author_name ? `${post.author_name} · ` : ""}
58+
{new Date(post.created_at).toLocaleString("ko-KR", {
59+
year: "numeric",
60+
month: "2-digit",
61+
day: "2-digit",
62+
hour: "2-digit",
63+
minute: "2-digit",
64+
})}
5865
</span>
5966
<div className="flex gap-2">
6067
{post.tags?.map((tag) => (

src/components/posts/SupabasePostsWithFilter.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ function draftToPost(draft: PostDraft): Post {
1212
frontmatter: {
1313
title: draft.title,
1414
description: "",
15-
date: draft.created_at.split("T")[0],
16-
author: "",
15+
date: new Date(draft.created_at).toLocaleString("ko-KR", {
16+
year: "numeric",
17+
month: "2-digit",
18+
day: "2-digit",
19+
hour: "2-digit",
20+
minute: "2-digit",
21+
}),
22+
author: draft.author_name ?? "",
1723
tags: draft.tags ?? [],
1824
},
1925
content: draft.body,

src/lib/drafts/published.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,54 @@ import type { PostDraft } from "@/lib/supabase/types";
44
export async function getPublishedPosts(): Promise<PostDraft[]> {
55
const { data, error } = await supabase
66
.from("post_drafts")
7-
.select("*")
7+
.select("*, profiles:author_id(display_name)")
88
.eq("status", "published")
99
.order("created_at", { ascending: false });
1010

1111
if (error) throw error;
12-
return (data as PostDraft[]) ?? [];
12+
return (
13+
(data ?? []).map((row: Record<string, unknown>) => {
14+
const profiles = row.profiles as { display_name: string } | null;
15+
return {
16+
...row,
17+
author_name: profiles?.display_name ?? "",
18+
profiles: undefined,
19+
} as PostDraft;
20+
})
21+
);
22+
}
23+
24+
function mapRowWithAuthor(row: Record<string, unknown>): PostDraft {
25+
const profiles = row.profiles as { display_name: string } | null;
26+
return {
27+
...row,
28+
author_name: profiles?.display_name ?? "",
29+
profiles: undefined,
30+
} as PostDraft;
1331
}
1432

1533
export async function getPublishedPostBySlug(
1634
slugOrId: string
1735
): Promise<PostDraft | null> {
36+
const selectFields = "*, profiles:author_id(display_name)";
37+
1838
// Try by slug first
1939
const { data: bySlug } = await supabase
2040
.from("post_drafts")
21-
.select("*")
41+
.select(selectFields)
2242
.eq("slug", slugOrId)
2343
.eq("status", "published")
2444
.maybeSingle();
2545

26-
if (bySlug) return bySlug as PostDraft;
46+
if (bySlug) return mapRowWithAuthor(bySlug as Record<string, unknown>);
2747

2848
// Fallback to id
2949
const { data: byId } = await supabase
3050
.from("post_drafts")
31-
.select("*")
51+
.select(selectFields)
3252
.eq("id", slugOrId)
3353
.eq("status", "published")
3454
.maybeSingle();
3555

36-
return (byId as PostDraft) ?? null;
56+
return byId ? mapRowWithAuthor(byId as Record<string, unknown>) : null;
3757
}

src/lib/supabase/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface PostDraft {
3737
status: DraftStatus;
3838
created_at: string;
3939
updated_at: string;
40+
author_name?: string;
4041
}
4142

4243
export interface Comment {

0 commit comments

Comments
 (0)