import type { GetStaticProps, GetStaticPaths, NextPage } from 'next' import Image from 'next/image' import { MDXRemote } from 'next-mdx-remote' import date from 'date-and-time' import Giscus from '@giscus/react' import { useTheme } from 'next-themes' import 'katex/dist/katex.min.css' import { Head } from 'components/Head' import { Header } from 'components/Header' import type { FooterProps } from 'components/Footer' import { Footer } from 'components/Footer' import type { Post } from 'utils/blog' interface BlogPostPageProps extends FooterProps { post: Post } const BlogPostPage: NextPage = (props) => { const { version, post } = props const { theme = 'dark' } = useTheme() return ( <> {post.frontmatter.title} {date.format(new Date(post.frontmatter.publishedOn), 'DD/MM/YYYY')} { const { src = '', alt = 'Blog Image' } = properties const source = src.replace('../public/', '/') return ( ) }, a: (props) => { if (props.href?.startsWith('#') ?? false) { return } return ( ) } }} /> > ) } export const getStaticProps: GetStaticProps = async ( context ) => { const slug = context?.params?.['slug'] const { getPostBySlug } = await import('utils/blog') const post = await getPostBySlug(slug) if (post == null || (post != null && !post.frontmatter.isPublished)) { return { redirect: { destination: '/404', permanent: false } } } const { readPackage } = await import('read-pkg') const { version } = await readPackage() return { props: { version, post } } } export const getStaticPaths: GetStaticPaths = async () => { const { getPosts } = await import('utils/blog') const posts = await getPosts() return { paths: posts.map((post) => { return { params: { slug: post.slug } } }), fallback: false } } export default BlogPostPage
{date.format(new Date(post.frontmatter.publishedOn), 'DD/MM/YYYY')}