Skip to content

Commit

Permalink
refactor: logic 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
XionWCFM committed Jan 30, 2025
1 parent f376483 commit b01aa3f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apps/blog/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { StaticHeader } from "~/widgets/header/static-header";

export default async function RootPage() {
const rawPosts = await getAllPosts();
const posts = rawPosts
.filter((post) => post.authority === "viewer" && isAfter(new Date(), parseISO(post.release_date)))
.sort((a, b) => compareDesc(parseISO(a.release_date), parseISO(b.release_date)));

const posts = createCurrentPost(rawPosts);
const currentPostTitle = `${AUTHOR_NICKNAME}의 최신 포스트 보기`;

return (
Expand Down Expand Up @@ -52,3 +49,9 @@ export default async function RootPage() {
</>
);
}

const createCurrentPost = <T extends { authority?: string; release_date: string }>(posts: T[]) => {
return posts
.filter((post) => post.authority === "viewer" && isAfter(new Date(), parseISO(post.release_date)))
.sort((a, b) => compareDesc(parseISO(a.release_date), parseISO(b.release_date)));
};

0 comments on commit b01aa3f

Please sign in to comment.