2022-09-04 20:40:58 +02:00
|
|
|
import type { GetStaticProps, NextPage } from 'next'
|
2021-11-08 15:10:26 +01:00
|
|
|
import Link from 'next/link'
|
|
|
|
import date from 'date-and-time'
|
|
|
|
|
|
|
|
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 { ShadowContainer } from 'components/design/ShadowContainer'
|
|
|
|
import type { PostMetadata } from 'utils/blog'
|
|
|
|
|
|
|
|
const blogDescription =
|
|
|
|
'The latest news about my journey of learning computer science.'
|
|
|
|
|
|
|
|
interface BlogPageProps extends FooterProps {
|
|
|
|
posts: PostMetadata[]
|
|
|
|
}
|
|
|
|
|
2021-12-04 15:52:51 +01:00
|
|
|
const BlogPage: NextPage<BlogPageProps> = (props) => {
|
2021-11-08 15:10:26 +01:00
|
|
|
const { version, posts } = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Head title='Blog | Divlo' description={blogDescription} />
|
|
|
|
|
|
|
|
<Header />
|
2021-12-04 15:52:51 +01:00
|
|
|
<main className='flex flex-1 flex-col flex-wrap items-center'>
|
|
|
|
<div className='mt-10 flex flex-col items-center'>
|
2021-11-08 15:10:26 +01:00
|
|
|
<h1 className='text-4xl font-semibold'>Blog</h1>
|
2022-02-23 00:38:50 +01:00
|
|
|
<p className='mt-6 text-center' data-cy='blog-post-date'>
|
2021-11-08 15:10:26 +01:00
|
|
|
{blogDescription}
|
|
|
|
</p>
|
|
|
|
</div>
|
2021-12-04 15:52:51 +01:00
|
|
|
<div className='flex w-full items-center justify-center p-8'>
|
2021-11-08 15:10:26 +01:00
|
|
|
<div className='w-[1600px]' data-cy='blog-posts'>
|
|
|
|
{posts.map((post, index) => {
|
|
|
|
const postPublishedOn = date.format(
|
|
|
|
new Date(post.frontmatter.publishedOn),
|
|
|
|
'DD/MM/YYYY'
|
|
|
|
)
|
|
|
|
return (
|
2022-10-27 19:13:29 +02:00
|
|
|
<Link
|
|
|
|
href={`/blog/${post.slug}`}
|
|
|
|
key={index}
|
|
|
|
locale='en'
|
|
|
|
data-cy={post.slug}
|
|
|
|
>
|
|
|
|
<ShadowContainer className='cursor-pointer p-6 transition duration-200 ease-in-out hover:-translate-y-2'>
|
|
|
|
<h2
|
|
|
|
data-cy='blog-post-title'
|
|
|
|
className='text-xl font-semibold'
|
|
|
|
>
|
|
|
|
{post.frontmatter.title}
|
|
|
|
</h2>
|
|
|
|
<p data-cy='blog-post-date' className='mt-2'>
|
|
|
|
{postPublishedOn}
|
|
|
|
</p>
|
|
|
|
<p data-cy='blog-post-description' className='mt-3'>
|
|
|
|
{post.frontmatter.description}
|
|
|
|
</p>
|
|
|
|
</ShadowContainer>
|
2021-11-08 15:10:26 +01:00
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
<Footer version={version} />
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getStaticProps: GetStaticProps<BlogPageProps> = async () => {
|
|
|
|
const { readPackage } = await import('read-pkg')
|
|
|
|
const { getPosts } = await import('utils/blog')
|
|
|
|
const posts = await getPosts()
|
|
|
|
const { version } = await readPackage()
|
|
|
|
return { props: { version, posts } }
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BlogPage
|