tailwind-nextjs-blog/layouts/PostSimple.tsx

85 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-10-17 23:37:01 +08:00
import Link from '@/components/Link';
import PageTitle from '@/components/PageTitle';
import SectionContainer from '@/components/SectionContainer';
import { BlogSEO } from '@/components/SEO';
import siteMetadata from '@/data/siteMetadata';
import formatDate from '@/lib/utils/formatDate';
import Comments from '@/components/comments';
import ScrollTopAndComment from '@/components/ScrollTopAndComment';
import { ReactNode } from 'react';
import { PostFrontMatter } from 'types/PostFrontMatter';
2022-07-17 21:40:41 +08:00
interface Props {
2022-10-17 23:37:01 +08:00
frontMatter: PostFrontMatter;
children: ReactNode;
next?: { slug: string; title: string };
prev?: { slug: string; title: string };
}
2022-10-17 23:37:01 +08:00
export default function PostLayout({
frontMatter,
next,
prev,
children,
}: Props) {
const { slug, date, title } = frontMatter;
2022-07-17 21:40:41 +08:00
return (
<SectionContainer>
<BlogSEO url={`${siteMetadata.siteUrl}/blog/${slug}`} {...frontMatter} />
2022-07-17 21:40:41 +08:00
<ScrollTopAndComment />
<article>
<div>
<header>
<div className="space-y-1 border-b border-gray-200 pb-10 text-center dark:border-gray-700">
<dl>
<div>
<dt className="sr-only">Published on</dt>
<dd className="text-base font-medium leading-6 text-gray-500 dark:text-gray-400">
<time dateTime={date}>{formatDate(date)}</time>
</dd>
</div>
</dl>
<div>
<PageTitle>{title}</PageTitle>
</div>
</div>
</header>
<div
className="divide-y divide-gray-200 pb-8 dark:divide-gray-700 xl:divide-y-0 "
2022-10-17 23:37:01 +08:00
style={{ gridTemplateRows: 'auto 1fr' }}>
2022-07-17 21:40:41 +08:00
<div className="divide-y divide-gray-200 dark:divide-gray-700 xl:col-span-3 xl:row-span-2 xl:pb-0">
2022-10-17 23:37:01 +08:00
<div className="prose max-w-none pt-10 pb-8 dark:prose-dark">
{children}
</div>
2022-07-17 21:40:41 +08:00
</div>
<Comments frontMatter={frontMatter} />
<footer>
<div className="flex flex-col text-sm font-medium sm:flex-row sm:justify-between sm:text-base">
{prev && (
<div className="pt-4 xl:pt-8">
<Link
href={`/blog/${prev.slug}`}
2022-10-17 23:37:01 +08:00
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400">
2022-07-17 21:40:41 +08:00
&larr; {prev.title}
</Link>
</div>
)}
{next && (
<div className="pt-4 xl:pt-8">
<Link
href={`/blog/${next.slug}`}
2022-10-17 23:37:01 +08:00
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400">
2022-07-17 21:40:41 +08:00
{next.title} &rarr;
</Link>
</div>
)}
</div>
</footer>
</div>
</div>
</article>
</SectionContainer>
2022-10-17 23:37:01 +08:00
);
2022-07-17 21:40:41 +08:00
}