diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-15 12:16:34 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-15 17:06:55 +0100 |
| commit | 0fa8ae55c52852c34c9143a6ec43c954c6404df1 (patch) | |
| tree | 32c5421025591386632c50200ce6bed3ce6e62b7 /src/components/PostsList | |
| parent | 15d247cb0d52d9c091fa040fe1d9d45e9e506050 (diff) | |
chore: retrieve posts list on blog page
Diffstat (limited to 'src/components/PostsList')
| -rw-r--r-- | src/components/PostsList/PostsList.module.scss | 5 | ||||
| -rw-r--r-- | src/components/PostsList/PostsList.tsx | 36 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/components/PostsList/PostsList.module.scss b/src/components/PostsList/PostsList.module.scss new file mode 100644 index 0000000..9f78f68 --- /dev/null +++ b/src/components/PostsList/PostsList.module.scss @@ -0,0 +1,5 @@ +@use "@styles/abstracts/placeholders"; + +.wrapper { + @extend %reset-ordered-list; +} diff --git a/src/components/PostsList/PostsList.tsx b/src/components/PostsList/PostsList.tsx new file mode 100644 index 0000000..ca3e788 --- /dev/null +++ b/src/components/PostsList/PostsList.tsx @@ -0,0 +1,36 @@ +import Link from 'next/link'; +import { ArticlePreview } from '@ts/types/articles'; +import styles from './PostsList.module.scss'; + +type TitleLevel = 2 | 3 | 4 | 5 | 6; + +const PostsList = ({ + posts, + titleLevel, +}: { + posts: ArticlePreview[]; + titleLevel: TitleLevel; +}) => { + const TitleTag = `h${titleLevel}` as keyof JSX.IntrinsicElements; + + const postsList = posts.map((post) => { + return ( + <li key={post.id}> + <article> + <header> + <TitleTag> + <Link href={`/article/${post.slug}`}> + <a>{post.title}</a> + </Link> + </TitleTag> + </header> + <div dangerouslySetInnerHTML={{ __html: post.content }}></div> + </article> + </li> + ); + }); + + return <ol className={styles.wrapper}>{postsList}</ol>; +}; + +export default PostsList; |
