Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript for Blog #1814

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/components/engineering/Blog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import matter from "gray-matter";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the js file should have been deleted but there's no file modifications for it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help

import fs from "fs";
import Link from "next/link";

interface Data {
date: string;
title: string;
author: string;
link: string;
}

const getBlogPost = async (): Promise<Data[]> => {
const directory = process.cwd() + "/src/engineering/";
const files = fs.readdirSync(directory);

return files.map((file) => {
const path = `${directory}/${file}`;
const contents = fs.readFileSync(path);
const markdown = matter(contents);

return markdown.data as Data;
});
};
const Blog = async () => {
const data = await getBlogPost();

const blogs = data.sort(
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime(),
);

return (
<>
<div className="m-auto mt-[10%] w-10/12">
<title>Engineering | Engineering Blogs</title>
<p className="m-0 text-center text-3xl font-bold md:text-left">
Engineering Blogs
</p>
<p className="my-3 w-full text-center md:w-3/4 md:text-left">
Check out our engineering blogs to learn more about the behind the
scenes as engineers discuss various challenges, migrations,
bottlenecks. Our engineering blogs captures how our engineers approach
problems and bring innovative solutions to the table.
</p>
<div className="my-8 grid w-full grid-cols-1 gap-4 md:grid-cols-3 xl:grid-cols-5">
{blogs.map(({ title, author, date, link }, index) => (
<Link
href={`/engineering/blog/${link}`}
key={index}
className="rounded-lg bg-hackathon-blue-200 px-3 py-2 text-white hover:cursor-pointer hover:opacity-80"
>
<p className="text-lg font-semibold">{title}</p>
<p className="text-sm text-gray-300">{author}</p>
<p className="flex justify-end text-sm text-gray-300">
{new Date(date).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
})}
</p>
</Link>
))}
</div>
</div>
</>
);
};

export default Blog;
Loading