feat: add related blog posts component

This commit is contained in:
Theodore Kruczek
2024-01-14 07:51:36 -05:00
parent 155a602203
commit 13cbe429cc
5 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
---
import { APP_BLOG } from "~/utils/config";
import { fetchPosts, getRelatedPosts } from "~/utils/blog";
import BlogHighlightedPosts from "../widgets/BlogHighlightedPosts.astro";
import type { Post } from "~/types";
import { getBlogPermalink } from "~/utils/permalinks";
export interface Props {
post: Post;
}
const { post } = Astro.props;
const fetchedPosts = await fetchPosts();
const relatedPosts = post.tags ? getRelatedPosts(fetchedPosts, post.slug, post.tags) : [];
---
{
APP_BLOG.isRelatedPostsEnabled ? (
<BlogHighlightedPosts
classes={{ container: "pt-0 lg:pt-0 md:pt-0" }}
title="Related Posts"
linkText="View All Posts"
linkUrl={getBlogPermalink()}
postIds={relatedPosts.map((post) => post.id)}
/>
) : null
}