jonbio/layouts/PostLayout.js

132 lines
5.7 KiB
JavaScript
Raw Normal View History

2021-01-09 17:50:45 +08:00
import Link from '@/components/Link'
import PageTitle from '@/components/PageTitle'
2021-02-25 00:04:02 +01:00
import SectionContainer from '@/components/SectionContainer'
2021-01-10 17:35:37 +08:00
import { BlogSeo } from '@/components/SEO'
2021-01-09 17:50:45 +08:00
import Tag from '@/components/Tag'
import siteMetadata from '@/data/siteMetadata'
2021-01-09 17:50:45 +08:00
const editUrl = (fileName) => `${siteMetadata.siteRepo}/blob/master/data/blog/${fileName}`
2021-01-09 17:50:45 +08:00
const discussUrl = (slug) =>
2021-05-10 17:07:13 -05:00
`https://mobile.twitter.com/search?q=${encodeURIComponent(
`${siteMetadata.siteUrl}/blog/${slug}`
)}`
2021-01-09 17:50:45 +08:00
2021-02-25 00:04:02 +01:00
const postDateTemplate = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }
2021-01-09 17:50:45 +08:00
2021-05-16 15:56:39 +08:00
export default function PostLayout({ frontMatter, authorDetails, next, prev, children }) {
2021-01-10 16:55:38 +08:00
const { slug, fileName, date, title, tags } = frontMatter
2021-01-09 17:50:45 +08:00
return (
<SectionContainer>
<BlogSeo url={`${siteMetadata.siteUrl}/blog/${frontMatter.slug}`} {...frontMatter} />
2021-02-04 08:50:28 +08:00
<article>
<div className="xl:divide-y xl:divide-gray-200 xl:dark:divide-gray-700">
<header className="pt-6 xl:pb-6">
<div className="space-y-1 text-center">
<dl className="space-y-10">
<div>
<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)}
2021-02-25 00:04:02 +01:00
</time>
2021-02-04 08:50:28 +08:00
</dd>
</div>
</dl>
2021-01-09 17:50:45 +08:00
<div>
2021-02-04 08:50:28 +08:00
<PageTitle>{title}</PageTitle>
2021-01-09 17:50:45 +08:00
</div>
</div>
2021-02-04 08:50:28 +08:00
</header>
<div
className="pb-8 divide-y divide-gray-200 xl:divide-y-0 dark:divide-gray-700 xl:grid xl:grid-cols-4 xl:gap-x-6"
style={{ gridTemplateRows: 'auto 1fr' }}
>
<dl className="pt-6 pb-10 xl:pt-11 xl:border-b xl:border-gray-200 xl:dark:border-gray-700">
<dt className="sr-only">Authors</dt>
<dd>
<ul className="flex justify-center space-x-8 xl:block sm:space-x-12 xl:space-x-0 xl:space-y-8">
<li className="flex items-center space-x-2">
<img src={siteMetadata.image} alt="avatar" className="w-10 h-10 rounded-full" />
2021-02-04 08:50:28 +08:00
<dl className="text-sm font-medium leading-5 whitespace-nowrap">
<dt className="sr-only">Name</dt>
2021-05-16 15:56:39 +08:00
<dd className="text-gray-900 dark:text-gray-100">{authorDetails.name}</dd>
2021-02-04 08:50:28 +08:00
<dt className="sr-only">Twitter</dt>
<dd>
<Link
2021-05-16 15:56:39 +08:00
href={authorDetails.twitter}
2021-02-04 08:50:28 +08:00
className="text-blue-500 hover:text-blue-600 dark:hover:text-blue-400"
>
2021-05-16 15:56:39 +08:00
{authorDetails.twitter.replace('https://twitter.com/', '@')}
2021-02-04 08:50:28 +08:00
</Link>
</dd>
</dl>
</li>
</ul>
</dd>
</dl>
<div className="divide-y divide-gray-200 dark:divide-gray-700 xl:pb-0 xl:col-span-3 xl:row-span-2">
<div className="pt-10 pb-8 prose dark:prose-dark max-w-none">{children}</div>
<div className="pt-6 pb-6 text-sm text-gray-700 dark:text-gray-300">
<Link href={discussUrl(slug)} rel="nofollow">
{'Discuss on Twitter'}
</Link>
{``}
<Link href={editUrl(fileName)}>{'View on GitHub'}</Link>
2021-01-09 17:50:45 +08:00
</div>
2021-02-04 08:50:28 +08:00
</div>
<footer>
<div className="text-sm font-medium leading-5 divide-gray-200 xl:divide-y dark:divide-gray-700 xl:col-start-1 xl:row-start-2">
{tags && (
<div className="py-4 xl:py-8">
2021-01-12 23:35:36 +08:00
<h2 className="text-xs tracking-wide text-gray-500 uppercase dark:text-gray-400">
2021-02-04 08:50:28 +08:00
Tags
2021-01-09 17:50:45 +08:00
</h2>
2021-02-12 16:40:09 +08:00
<div className="flex flex-wrap">
2021-02-04 08:50:28 +08:00
{tags.map((tag) => (
<Tag key={tag} text={tag} />
))}
2021-01-09 17:50:45 +08:00
</div>
</div>
)}
2021-02-04 08:50:28 +08:00
{(next || prev) && (
<div className="flex justify-between py-4 xl:block xl:space-y-8 xl:py-8">
{prev && (
<div>
<h2 className="text-xs tracking-wide text-gray-500 uppercase dark:text-gray-400">
Previous Article
</h2>
<div className="text-blue-500 hover:text-blue-600 dark:hover:text-blue-400">
<Link href={`/blog/${prev.slug}`}>{prev.title}</Link>
</div>
</div>
)}
{next && (
<div>
<h2 className="text-xs tracking-wide text-gray-500 uppercase dark:text-gray-400">
Next Article
</h2>
<div className="text-blue-500 hover:text-blue-600 dark:hover:text-blue-400">
<Link href={`/blog/${next.slug}`}>{next.title}</Link>
</div>
</div>
)}
2021-01-09 17:50:45 +08:00
</div>
)}
</div>
2021-02-04 08:50:28 +08:00
<div className="pt-4 xl:pt-8">
<Link
href="/blog"
className="text-blue-500 hover:text-blue-600 dark:hover:text-blue-400"
>
&larr; Back to the blog
</Link>
</div>
</footer>
</div>
2021-01-09 17:50:45 +08:00
</div>
</article>
</SectionContainer>
)
}