-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(HTD-54): add related posts (#78)
* feat(HTD-54): add related posts * fix(HTD-54): add missing key * fix(HTD-54): typo * fix(HTD-54): filter out current post from related post content
- Loading branch information
Showing
6 changed files
with
103 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { StyledRelatedPostWrapper, StyledRelatedPostsGrid } from './related-posts.styles'; | ||
|
||
import Stack from '@/components/elements/stack'; | ||
import { BlogCard } from '@/components/modules/blog-card'; | ||
import { HeadingBlock } from '@/components/modules/heading-block'; | ||
import { getRelatedPosts } from '@/lib/mdx'; | ||
|
||
interface RelatedPostsProps { | ||
tags: string[]; | ||
currentPostSlug: string; | ||
} | ||
|
||
export const RelatedPosts = async ({ tags, currentPostSlug }: RelatedPostsProps) => { | ||
const relatedPosts = await getRelatedPosts({ tags, currentPostSlug }); | ||
|
||
if (relatedPosts.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<StyledRelatedPostWrapper> | ||
<Stack $gap="32px" $gapxl="48px"> | ||
<HeadingBlock title="Related `*content*`" $align="center" $isContentCentered /> | ||
<StyledRelatedPostsGrid> | ||
{relatedPosts.length && | ||
relatedPosts.map(post => ( | ||
<BlogCard | ||
key={post.slug} | ||
title={post.title} | ||
slug={post.slug} | ||
image={{ src: `/images/${post.coverImage}`, alt: post.title }} | ||
date={post.date} | ||
tag={post.tags[0]} | ||
// TODO(gerald): Replace with the excerpt when working on blog post content | ||
text="Sometimes things crash when they're running inside a Docker container though, and then all of a sudden it can get much more difficult to work out why, or what the hell to do next." | ||
/> | ||
))} | ||
</StyledRelatedPostsGrid> | ||
</Stack> | ||
</StyledRelatedPostWrapper> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
src/components/sections/blog/related-posts/related-posts.styles.ts
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,27 @@ | ||
'use client'; | ||
|
||
import { screens, styled } from '@/styles'; | ||
|
||
export const StyledRelatedPostWrapper = styled.section` | ||
padding: 32px 0; | ||
margin: 32px 0; | ||
@media (min-width: ${screens['lg']}) { | ||
padding: 48px 0; | ||
margin: 48px 0; | ||
} | ||
`; | ||
|
||
export const StyledRelatedPostsGrid = styled.div` | ||
display: grid; | ||
grid-template-columns: 1fr; /* 1 column on mobile */ | ||
gap: 24px; | ||
@media (min-width: ${screens['lg']}) { | ||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); | ||
} | ||
& article { | ||
max-width: 434px; | ||
} | ||
`; |
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