tailwind-nextjs-blog/layouts/PostSimple.tsx

92 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-08-16 23:55:57 +08:00
import { ReactNode } from 'react';
import { formatDate } from 'pliny/utils/formatDate';
import { CoreContent } from 'pliny/utils/contentlayer';
import type { Blog } from 'contentlayer/generated';
import Comments from '@/components/Comments';
import Link from '@/components/Link';
import PageTitle from '@/components/PageTitle';
import SectionContainer from '@/components/SectionContainer';
import siteMetadata from '@/data/siteMetadata';
import ScrollTopAndComment from '@/components/ScrollTopAndComment';
2022-07-17 21:40:41 +08:00
interface LayoutProps {
2023-08-16 23:55:57 +08:00
content: CoreContent<Blog>;
children: ReactNode;
next?: { path: string; title: string };
prev?: { path: string; title: string };
}
2023-08-16 23:55:57 +08:00
export default function PostLayout({
content,
next,
prev,
children,
}: LayoutProps) {
const { path, slug, date, title } = content;
2022-07-17 21:40:41 +08:00
return (
<SectionContainer>
<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">
2023-08-16 23:55:57 +08:00
<time dateTime={date}>
{formatDate(date, siteMetadata.locale)}
</time>
2022-07-17 21:40:41 +08:00
</dd>
</div>
</dl>
<div>
<PageTitle>{title}</PageTitle>
</div>
</div>
</header>
<div className="grid-rows-[auto_1fr] divide-y divide-gray-200 pb-8 dark:divide-gray-700 xl:divide-y-0">
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">
2023-08-16 23:55:57 +08:00
<div className="prose max-w-none pb-8 pt-10 dark:prose-invert">
{children}
</div>
2022-07-17 21:40:41 +08:00
</div>
{siteMetadata.comments && (
2023-08-16 23:55:57 +08:00
<div
className="pb-6 pt-6 text-center text-gray-700 dark:text-gray-300"
id="comment">
<Comments slug={slug} />
</div>
)}
2022-07-17 21:40:41 +08:00
<footer>
<div className="flex flex-col text-sm font-medium sm:flex-row sm:justify-between sm:text-base">
{prev && prev.path && (
2022-07-17 21:40:41 +08:00
<div className="pt-4 xl:pt-8">
<Link
href={`/${prev.path}`}
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
2023-08-16 23:55:57 +08:00
aria-label={`Previous post: ${prev.title}`}>
2022-07-17 21:40:41 +08:00
&larr; {prev.title}
</Link>
</div>
)}
{next && next.path && (
2022-07-17 21:40:41 +08:00
<div className="pt-4 xl:pt-8">
<Link
href={`/${next.path}`}
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
2023-08-16 23:55:57 +08:00
aria-label={`Next post: ${next.title}`}>
2022-07-17 21:40:41 +08:00
{next.title} &rarr;
</Link>
</div>
)}
</div>
</footer>
</div>
</div>
</article>
</SectionContainer>
2023-08-16 23:55:57 +08:00
);
2022-07-17 21:40:41 +08:00
}