-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
248 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Link from "next/link"; | ||
import { css, styled } from "styled-components"; | ||
import { getPostBySeriesId } from "@src/entities/post"; | ||
import { SeriesMap } from "@src/entities/series/consts/series"; | ||
|
||
export const SeriesPostTitleList = ({ | ||
seriesId, | ||
currentPostId, | ||
defaultOpen = false, | ||
}: { | ||
seriesId: string; | ||
currentPostId?: number; | ||
defaultOpen?: boolean; | ||
}) => { | ||
const series = SeriesMap.get(seriesId); | ||
if (!series) return <></>; | ||
|
||
const posts = getPostBySeriesId(seriesId); | ||
|
||
return ( | ||
<Container open={defaultOpen}> | ||
<Title> | ||
<SeriesTitle>{series.title}</SeriesTitle> 시리즈의 다른 글 | ||
</Title> | ||
<ol> | ||
{posts.map((post) => ( | ||
<ListItem | ||
key={post.meta.index} | ||
highlighted={post.meta.index === currentPostId} | ||
> | ||
<Link href={"/" + post.slug}>{post.meta.title}</Link> | ||
</ListItem> | ||
))} | ||
</ol> | ||
</Container> | ||
); | ||
}; | ||
|
||
const Container = styled.details` | ||
background-color: ${({ theme }) => theme.colors.bg.secondary}; | ||
padding: 24px; | ||
border-radius: 10px; | ||
ol { | ||
padding-inline-start: 1.2rem; | ||
margin-block-end: 0; | ||
margin-block-start: 12px; | ||
} | ||
`; | ||
|
||
const Title = styled.summary` | ||
font-size: ${({ theme }) => theme.fontSizes.m}; | ||
`; | ||
|
||
const SeriesTitle = styled.span` | ||
font-weight: bold; | ||
margin-left: 4px; | ||
`; | ||
|
||
const ListItem = styled.li<{ highlighted: boolean }>` | ||
color: ${({ theme }) => theme.colors.text.placeholder}; | ||
${({ highlighted, theme }) => | ||
highlighted && | ||
css` | ||
color: ${theme.colors.primaryLight}; | ||
`} | ||
&:hover { | ||
text-decoration: underline; | ||
color: ${({ theme, highlighted }) => | ||
highlighted ? theme.colors.primaryBrighter : theme.colors.text.primary}; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { compareDesc } from "date-fns"; | ||
import { Post, allPosts } from "contentlayer/generated"; | ||
import { PostListElement } from "@src/types/post"; | ||
|
||
const getSortedPosts = (type: "desc" | "asc" = "desc") => { | ||
return allPosts.sort((a, b) => { | ||
const compareByDate = | ||
compareDesc(new Date(a.date), new Date(b.date)) * | ||
(type === "desc" ? 1 : -1); | ||
if (compareByDate !== 0) return compareByDate; | ||
return b.id - a.id; | ||
}); | ||
}; | ||
|
||
const convertPostToPostListElement = (meta: Post) => { | ||
return { | ||
slug: meta.url, | ||
meta: { | ||
index: meta.id, | ||
title: meta.title, | ||
description: meta.description || "", | ||
postedAt: meta.date, | ||
category: "", | ||
series: "", | ||
tags: [], | ||
keywords: [], | ||
}, | ||
} satisfies PostListElement; | ||
}; | ||
|
||
export const getAllPostMeta = (): PostListElement[] => { | ||
return getSortedPosts().map(convertPostToPostListElement); | ||
}; | ||
|
||
export const getPostDetail = (slug: string) => { | ||
const sorted = getSortedPosts(); | ||
const postIdx = sorted.findIndex((post) => post._raw.flattenedPath === slug); | ||
return { | ||
postIdx, | ||
detail: sorted[postIdx], | ||
}; | ||
}; | ||
|
||
export const getPostMeta = (idx: number) => { | ||
return getSortedPosts()[idx]; | ||
}; | ||
|
||
export const getPostBySeriesId = (seriesId: string) => { | ||
return getSortedPosts("asc") | ||
.filter((post) => post.seriesId === seriesId) | ||
.map(convertPostToPostListElement); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Series } from "../types/Series"; | ||
|
||
export const SeriesMap = new Map<Series["id"], Series>([ | ||
[ | ||
"web-frontend-test", | ||
{ id: "web-frontend-test", title: "프론트엔드 테스트 가이드" }, | ||
], | ||
[ | ||
"custom-ssr-server", | ||
{ id: "custom-ssr-server", title: "직접 만들어 보는 SSR 서버" }, | ||
], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type Series = { | ||
id: string; | ||
title: string; | ||
}; |
Oops, something went wrong.