import { GetStaticPaths, GetStaticProps } from "next"; import fs from "fs"; import { ParsedUrlQuery } from "querystring"; import { BLOGS_PATH, getFileContentBySlug, renderMarkdown, } from "../../utils/markdown"; import { MarkdownRenderingResult } from "../../types/types"; import { MainLayout } from "../../layouts/MainLayout"; import Link from "next/link"; import { IoMdArrowRoundBack as BackIcon } from "react-icons/io"; import { BasicBlogProps } from "."; export const BlogArticle = ({ frontMatter, html }: MarkdownRenderingResult) => { const { title, author, date, description, authorLink } = frontMatter as BasicBlogProps; return ( Go Back {date} {title} By{" "} {authorLink && ( @{author} )} {!authorLink && @{author}} {description} ); }; interface BlogProps extends ParsedUrlQuery { slug: string; } export const getStaticPaths: GetStaticPaths = async () => { const paths = fs .readdirSync(BLOGS_PATH) .map((path) => path.replace(/\.mdx?$/, "")) .map((slug) => ({ params: { slug } })); return { paths, fallback: false, }; }; export const getStaticProps: GetStaticProps = async ({ params, }) => { const markdownContent = getFileContentBySlug(params?.slug as string); const renderedHTML = await renderMarkdown(markdownContent.content); return { props: { frontMatter: markdownContent.frontMatter, html: renderedHTML, }, }; }; export default BlogArticle;