2021-01-10 15:45:45 +08:00
|
|
|
import Link from '@/components/Link'
|
2021-01-10 17:35:37 +08:00
|
|
|
import { PageSeo } from '@/components/SEO'
|
2021-02-25 00:04:02 +01:00
|
|
|
import Tag from '@/components/Tag'
|
|
|
|
import siteMetadata from '@/data/siteMetadata'
|
|
|
|
import { getAllFilesFrontMatter } from '@/lib/mdx'
|
2021-01-09 17:50:45 +08:00
|
|
|
|
|
|
|
const MAX_DISPLAY = 5
|
2021-02-25 00:04:02 +01:00
|
|
|
const postDateTemplate = { year: 'numeric', month: 'long', day: 'numeric' }
|
2021-01-09 17:50:45 +08:00
|
|
|
|
|
|
|
export async function getStaticProps() {
|
|
|
|
const posts = await getAllFilesFrontMatter('blog')
|
|
|
|
|
|
|
|
return { props: { posts } }
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Home({ posts }) {
|
|
|
|
return (
|
2021-01-10 15:45:45 +08:00
|
|
|
<>
|
2021-01-10 17:35:37 +08:00
|
|
|
<PageSeo
|
2021-01-10 15:45:45 +08:00
|
|
|
title={siteMetadata.title}
|
|
|
|
description={siteMetadata.description}
|
2021-01-10 17:35:37 +08:00
|
|
|
url={siteMetadata.siteUrl}
|
2021-01-10 15:45:45 +08:00
|
|
|
/>
|
2021-01-09 17:50:45 +08:00
|
|
|
<div className="divide-y divide-gray-200 dark:divide-gray-700">
|
|
|
|
<div className="pt-6 pb-8 space-y-2 md:space-y-5">
|
2021-01-12 23:35:36 +08:00
|
|
|
<h1 className="text-3xl font-extrabold leading-9 tracking-tight text-gray-900 dark:text-gray-100 sm:text-4xl sm:leading-10 md:text-6xl md:leading-14">
|
2021-01-09 17:50:45 +08:00
|
|
|
Latest
|
|
|
|
</h1>
|
|
|
|
<p className="text-lg leading-7 text-gray-500 dark:text-gray-400">
|
|
|
|
{siteMetadata.description}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<ul className="divide-y divide-gray-200 dark:divide-gray-700">
|
|
|
|
{!posts.length && 'No posts found.'}
|
|
|
|
{posts.slice(0, MAX_DISPLAY).map((frontMatter) => {
|
|
|
|
const { slug, date, title, summary, tags } = frontMatter
|
|
|
|
return (
|
|
|
|
<li key={slug} className="py-12">
|
2021-02-04 08:44:28 +08:00
|
|
|
<article>
|
|
|
|
<div className="space-y-2 xl:grid xl:grid-cols-4 xl:space-y-0 xl:items-baseline">
|
|
|
|
<dl>
|
|
|
|
<dt className="sr-only">Published on</dt>
|
|
|
|
<dd className="text-base font-medium leading-6 text-gray-500 dark:text-gray-400">
|
2021-02-25 00:04:02 +01:00
|
|
|
<time dateTime={date}>
|
|
|
|
{new Date(date).toLocaleDateString(siteMetadata.locale, postDateTemplate)}
|
|
|
|
</time>
|
2021-02-04 08:44:28 +08:00
|
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
<div className="space-y-5 xl:col-span-3">
|
|
|
|
<div className="space-y-6">
|
|
|
|
<div>
|
|
|
|
<h2 className="text-2xl font-bold leading-8 tracking-tight">
|
|
|
|
<Link
|
|
|
|
href={`/blog/${slug}`}
|
|
|
|
className="text-gray-900 dark:text-gray-100"
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</Link>
|
|
|
|
</h2>
|
2021-02-06 16:54:20 +08:00
|
|
|
<div className="flex flex-wrap">
|
2021-02-04 08:44:28 +08:00
|
|
|
{tags.map((tag) => (
|
|
|
|
<Tag key={tag} text={tag} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="prose text-gray-500 max-w-none dark:text-gray-400">
|
|
|
|
{summary}
|
2021-01-09 17:50:45 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 08:44:28 +08:00
|
|
|
<div className="text-base font-medium leading-6">
|
|
|
|
<Link
|
|
|
|
href={`/blog/${slug}`}
|
2021-06-19 17:40:01 +08:00
|
|
|
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
|
2021-02-04 08:44:28 +08:00
|
|
|
aria-label={`Read "${title}"`}
|
|
|
|
>
|
|
|
|
Read more →
|
|
|
|
</Link>
|
2021-01-09 17:50:45 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
{posts.length > MAX_DISPLAY && (
|
2021-01-12 23:35:36 +08:00
|
|
|
<div className="flex justify-end text-base font-medium leading-6">
|
2021-01-10 16:09:38 +08:00
|
|
|
<Link
|
|
|
|
href="/blog"
|
2021-06-19 17:40:01 +08:00
|
|
|
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
|
2021-01-10 16:09:38 +08:00
|
|
|
aria-label="all posts"
|
|
|
|
>
|
|
|
|
All Posts →
|
2021-01-09 17:50:45 +08:00
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)}
|
2021-01-10 15:45:45 +08:00
|
|
|
</>
|
2021-01-09 17:50:45 +08:00
|
|
|
)
|
|
|
|
}
|