This commit is contained in:
76
pages/projects/index.tsx
Normal file
76
pages/projects/index.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
import { GetServerSideProps } from "next";
|
||||
import { MainLayout } from "../../layouts/MainLayout";
|
||||
import { Post, getAllProjectsFrontMatter } from "../../utils/markdown";
|
||||
import { FrontMatter } from "../../types/types";
|
||||
import Link from "next/link";
|
||||
import { formatDate } from "../../utils/general";
|
||||
|
||||
export interface BasicProjectProps extends FrontMatter {
|
||||
title: string;
|
||||
description: string;
|
||||
date: string;
|
||||
author: string;
|
||||
authorLink: string;
|
||||
thumbnail: string;
|
||||
}
|
||||
|
||||
const ProjectCard = ({
|
||||
project,
|
||||
slug,
|
||||
}: {
|
||||
project: BasicProjectProps;
|
||||
slug: string;
|
||||
}) => {
|
||||
return (
|
||||
<div className="p-4 rounded-md border border-gray-700 grid grid-cols-1 xl:grid-cols-2 items-center gap-4">
|
||||
<div className="order-last xl:order-1">
|
||||
<div className="text-sm font-medium text-gray-500">
|
||||
{formatDate(project.date)}
|
||||
</div>
|
||||
<h2 className="text-2xl font-bold">{project.title}</h2>
|
||||
<p className="text-gray-400 text-lg">{project.description}</p>
|
||||
<Link href={`project/${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>
|
||||
{project.thumbnail && (
|
||||
<img
|
||||
src={project.thumbnail}
|
||||
alt={`${slug}-thumbnail`}
|
||||
className="w-full xl:h-40 h-auto object-cover rounded-md order-1 xl:order-last"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const Projects = ({ posts }: { posts: Post[] }) => {
|
||||
return (
|
||||
<MainLayout>
|
||||
<h1 className="text-3xl font-bold">Projects</h1>
|
||||
<div className="w-full h-0.5 bg-white/50 my-4 rounded-full" />
|
||||
<div className="grid grid-cols-1 gap-4">
|
||||
{posts.map((post, index) => (
|
||||
<ProjectCard
|
||||
key={index}
|
||||
project={post.frontMatter as BasicProjectProps}
|
||||
slug={post.slug}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async () => {
|
||||
const posts = getAllProjectsFrontMatter();
|
||||
return {
|
||||
props: {
|
||||
posts,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default Projects;
|
||||
Reference in New Issue
Block a user