-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
121 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
import React from "react"; | ||
import { AiOutlineStar } from "react-icons/ai"; | ||
import moment from "moment"; | ||
|
||
const BlogItem = ({ blog }) => { | ||
return ( | ||
<div className="overflow-hidden hover:text-white hover:bg-red-600 border-t border-red-600 duration-300"> | ||
<div className="flex gap-5 w-full duration-300"> | ||
<div className="w-[30rem] flex items-center rounded-md p-5 lg:h-[24rem]"> | ||
<Image | ||
src={blog.imageUrl} | ||
alt={blog.title} | ||
width={640} | ||
height={360} | ||
priority | ||
className="w-full h-full object-fill" | ||
/> | ||
</div> | ||
|
||
<div className="flex flex-col w-4/5 mx-10 justify-between py-10 text-red-600 lg:h-[24rem] hover:text-white gap-2"> | ||
<div className="flex gap-5"> | ||
<span className="font-semibold">{blog.tags}</span> | ||
<span className="font-normal text-base"> | ||
Post on: {moment(blog.createdAt).format("DD MMM YY. hh:mm A")} | ||
</span> | ||
</div> | ||
<h3 className="text-6xl font-ligh overflow-hidden">{blog.title}</h3> | ||
<p>{blog.author}</p> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BlogItem; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,12 @@ | ||
import { getAllBlogs } from "@/prisma/blogs"; | ||
|
||
export default async function handler(req, res) { | ||
try { | ||
if (req.method === "GET") { | ||
const blogs = await getAllBlogs(); | ||
return res.status(200).json(blogs); | ||
} | ||
} catch (error) { | ||
return res.status(500).json({ message: error.message }); | ||
} | ||
} |
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,38 @@ | ||
import BlogItem from "@/components/BlogItem"; | ||
import { getAllBlogs } from "@/prisma/blogs"; | ||
|
||
const BlogsPage = ({ blogs }) => { | ||
return ( | ||
<div className="flex flex-col gap-10 min-h-screen"> | ||
<div className="title flex flex-col items-center justify-center blog-title w-auto h-96 bg-no-repeat bg-cover bg-center"> | ||
<h2 className="uppercase font-extralight text-white text-8xl"> | ||
Our Blog | ||
</h2> | ||
</div> | ||
|
||
<div className="grid gap-10"> | ||
{blogs.map((blog) => ( | ||
<BlogItem key={blog.id} blog={blog} /> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BlogsPage; | ||
|
||
export const getServerSideProps = async () => { | ||
const blogs = await getAllBlogs(); | ||
|
||
const updatedBlogs = blogs.map((blog) => ({ | ||
...blog, | ||
updatedAt: blog.updatedAt.toString(), | ||
createdAt: blog.createdAt.toString(), | ||
})); | ||
|
||
return { | ||
props: { | ||
blogs: updatedBlogs, | ||
}, | ||
}; | ||
}; |
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,7 @@ | ||
import prisma from "./prisma"; | ||
|
||
// Get all blogs | ||
export const getAllBlogs = async () => { | ||
const blogs = await prisma.blog.findMany({}); | ||
return blogs; | ||
}; |
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