import fs from "fs"; import path from "path"; import { GetStaticProps, NextPage } from "next"; import matter from "gray-matter"; import ArticleCard from "components/ArticleCard"; import { VStack } from "@chakra-ui/react"; export interface BlogMetadata { title: string; cover_image: string; author: string; date: string; author_avatar_url: string; tags: string[]; summary: string; } export interface BlogPost { slug: string; metadata: BlogMetadata; } interface Props { posts: BlogPost[]; } const Blog: NextPage = ({ posts }) => { return ( {posts.map((post) => { return ( ); })} ); }; export default Blog; export const getStaticProps: GetStaticProps = async () => { const posts = fs.readdirSync("posts").map((file) => { return { slug: file.replace(".md", ""), metadata: matter(fs.readFileSync(path.join("posts", file))) .data as BlogMetadata, }; }); return { props: { posts: posts.sort( // @ts-ignore (a, b) => new Date(b.metadata.date) - new Date(a.metadata.date) ), }, }; };