All checks were successful
continuous-integration/drone/push Build is passing
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { GetServerSideProps } from "next";
|
|
import { MainLayout } from "../../layouts/MainLayout";
|
|
import { Post, getAllBlogsFrontMatter } from "../../utils/markdown";
|
|
import Link from "next/link";
|
|
import { formatDate } from "../../utils/general";
|
|
import { BasicArticleProps } from "../../components/PostHeader";
|
|
|
|
const BlogCard = ({
|
|
blog,
|
|
slug,
|
|
}: {
|
|
blog: BasicArticleProps;
|
|
slug: string;
|
|
}) => {
|
|
return (
|
|
<div className="p-4 rounded-md border border-gray-200 shadow-md shadow-gray-200 dark:shadow-gray-900 dark:border-gray-700 bg-black bg-opacity-60">
|
|
<div className="text-sm font-medium text-gray-500">
|
|
{formatDate(blog.date)}
|
|
</div>
|
|
<h2 className="text-2xl font-bold">{blog.title}</h2>
|
|
<p className="text-gray-600 dark:text-gray-400 text-sm">
|
|
{blog.description}
|
|
</p>
|
|
<Link href={`blog/${slug}`}>
|
|
<button className="bg-action px-2 py-1 rounded-md mt-4 hover:bg-action/60 transition-all ease-in duration-100 font-bold text-white">
|
|
Read more
|
|
</button>
|
|
</Link>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const Blog = ({ posts }: { posts: Post[] }) => {
|
|
return (
|
|
<MainLayout>
|
|
<h1 className="text-3xl font-bold text-gray-800 dark:text-gray-200">
|
|
Blog
|
|
</h1>
|
|
<div className="w-full h-0.5 bg-violet-200 dark:bg-violet-700 my-4 rounded-full" />
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
{posts.map((post, index) => (
|
|
<BlogCard
|
|
key={index}
|
|
blog={post.frontMatter as BasicArticleProps}
|
|
slug={post.slug}
|
|
/>
|
|
))}
|
|
</div>
|
|
</MainLayout>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps: GetServerSideProps = async () => {
|
|
const posts = getAllBlogsFrontMatter();
|
|
return {
|
|
props: {
|
|
posts,
|
|
},
|
|
};
|
|
};
|
|
|
|
export default Blog;
|