2022-09-04 20:40:58 +02:00
|
|
|
import type { GetStaticProps, GetStaticPaths, NextPage } from 'next'
|
2023-06-16 23:14:25 +02:00
|
|
|
import Link from 'next/link'
|
2023-05-21 18:21:46 +02:00
|
|
|
import Image from 'next/image'
|
2021-11-08 15:10:26 +01:00
|
|
|
import { MDXRemote } from 'next-mdx-remote'
|
2023-06-16 23:14:25 +02:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
|
|
|
import { faLink } from '@fortawesome/free-solid-svg-icons'
|
2021-11-08 15:10:26 +01:00
|
|
|
import date from 'date-and-time'
|
2022-08-23 12:23:31 +02:00
|
|
|
import Giscus from '@giscus/react'
|
|
|
|
import { useTheme } from 'next-themes'
|
2021-11-08 15:10:26 +01:00
|
|
|
|
2023-05-21 14:42:53 +02:00
|
|
|
import 'katex/dist/katex.min.css'
|
|
|
|
|
2021-11-08 15:10:26 +01:00
|
|
|
import { Head } from 'components/Head'
|
|
|
|
import { Header } from 'components/Header'
|
2022-09-04 20:40:58 +02:00
|
|
|
import type { FooterProps } from 'components/Footer'
|
|
|
|
import { Footer } from 'components/Footer'
|
2021-11-08 15:10:26 +01:00
|
|
|
import type { Post } from 'utils/blog'
|
|
|
|
|
|
|
|
interface BlogPostPageProps extends FooterProps {
|
|
|
|
post: Post
|
|
|
|
}
|
|
|
|
|
2023-06-16 23:14:25 +02:00
|
|
|
const Heading = (
|
|
|
|
props: React.DetailedHTMLProps<
|
|
|
|
React.HTMLAttributes<HTMLHeadingElement>,
|
|
|
|
HTMLHeadingElement
|
|
|
|
>
|
|
|
|
): JSX.Element => {
|
|
|
|
const { children, id = '' } = props
|
|
|
|
return (
|
|
|
|
<h2 {...props} className='group'>
|
|
|
|
<Link
|
|
|
|
href={`#${id}`}
|
|
|
|
className='invisible !text-black group-hover:visible dark:!text-white'
|
|
|
|
>
|
|
|
|
<FontAwesomeIcon className='mr-2 inline h-4 w-4' icon={faLink} />
|
|
|
|
</Link>
|
|
|
|
{children}
|
|
|
|
</h2>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-04 15:52:51 +01:00
|
|
|
const BlogPostPage: NextPage<BlogPostPageProps> = (props) => {
|
2021-11-08 15:10:26 +01:00
|
|
|
const { version, post } = props
|
|
|
|
|
2022-08-23 12:23:31 +02:00
|
|
|
const { theme = 'dark' } = useTheme()
|
|
|
|
|
2021-11-08 15:10:26 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Head
|
2023-05-30 21:51:27 +02:00
|
|
|
title={`${post.frontmatter.title} | Théo LUDWIG`}
|
2021-11-08 15:10:26 +01:00
|
|
|
description={post.frontmatter.description}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Header />
|
2023-05-21 18:21:46 +02:00
|
|
|
<main className='break-wrap-words flex flex-1 flex-col flex-wrap items-center'>
|
|
|
|
<div className='my-10 flex flex-col items-center text-center'>
|
2021-11-08 15:10:26 +01:00
|
|
|
<h1 className='text-3xl font-semibold'>{post.frontmatter.title}</h1>
|
|
|
|
<p className='mt-2' data-cy='blog-post-date'>
|
|
|
|
{date.format(new Date(post.frontmatter.publishedOn), 'DD/MM/YYYY')}
|
|
|
|
</p>
|
|
|
|
</div>
|
2023-05-21 18:21:46 +02:00
|
|
|
<div className='prose mb-10'>
|
|
|
|
<div className='px-8'>
|
|
|
|
<MDXRemote
|
|
|
|
{...post.source}
|
|
|
|
components={{
|
2023-06-16 23:14:25 +02:00
|
|
|
h1: Heading,
|
|
|
|
h2: Heading,
|
|
|
|
h3: Heading,
|
|
|
|
h4: Heading,
|
|
|
|
h5: Heading,
|
|
|
|
h6: Heading,
|
2023-05-21 18:21:46 +02:00
|
|
|
img: (properties) => {
|
|
|
|
const { src = '', alt = 'Blog Image' } = properties
|
|
|
|
const source = src.replace('../public/', '/')
|
|
|
|
return (
|
|
|
|
<span className='flex flex-col items-center justify-center'>
|
|
|
|
<Image
|
|
|
|
src={source}
|
|
|
|
alt={alt}
|
|
|
|
width={1000}
|
|
|
|
height={1000}
|
|
|
|
className='h-auto w-auto'
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
a: (props) => {
|
|
|
|
if (props.href?.startsWith('#') ?? false) {
|
|
|
|
return <a {...props} />
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<a target='_blank' rel='noopener noreferrer' {...props} />
|
|
|
|
)
|
2021-11-09 15:14:31 +01:00
|
|
|
}
|
2023-05-21 18:21:46 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Giscus
|
|
|
|
id='comments'
|
2023-05-31 20:09:08 +02:00
|
|
|
repo='theoludwig/theoludwig'
|
2023-05-21 18:21:46 +02:00
|
|
|
repoId='MDEwOlJlcG9zaXRvcnkzNTg5NDg1NDQ='
|
|
|
|
category='General'
|
|
|
|
categoryId='DIC_kwDOFWUewM4CQ_WK'
|
|
|
|
mapping='pathname'
|
|
|
|
reactionsEnabled='1'
|
|
|
|
emitMetadata='0'
|
|
|
|
inputPosition='top'
|
|
|
|
theme={theme}
|
|
|
|
lang='en'
|
|
|
|
loading='lazy'
|
|
|
|
/>
|
|
|
|
</div>
|
2021-11-08 15:10:26 +01:00
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
<Footer version={version} />
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getStaticProps: GetStaticProps<BlogPostPageProps> = async (
|
|
|
|
context
|
|
|
|
) => {
|
2023-01-10 23:56:46 +01:00
|
|
|
const slug = context?.params?.['slug']
|
2021-11-08 15:10:26 +01:00
|
|
|
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
|