portfolio/src/components/ArticleLayout.tsx

111 lines
3.7 KiB
TypeScript
Raw Normal View History

2023-01-17 21:24:16 +00:00
import {ReactNode} from 'react'
2022-12-06 12:54:34 +00:00
import Head from 'next/head'
2023-01-14 19:31:05 +00:00
import {usePathname} from 'next/navigation'
import {Container} from './Container'
2022-12-06 12:54:34 +00:00
import {formatDate} from '@/lib/formatDate'
2023-01-14 19:31:05 +00:00
import {Prose} from './Prose'
2023-01-17 21:24:16 +00:00
import {Views} from '@/components/Views'
2022-12-06 12:54:34 +00:00
2023-01-14 23:18:52 +00:00
type ArticleLayout = {
children?: ReactNode
isRssFeed: boolean
title: string
description: string
ogImage: string
date: string
2023-01-17 21:24:16 +00:00
slug: string
2023-01-14 23:18:52 +00:00
}
2022-12-06 12:54:34 +00:00
export function ArticleLayout({
children,
isRssFeed = false,
2023-01-14 19:31:05 +00:00
title,
description,
ogImage,
2023-01-17 21:24:16 +00:00
date,
slug
2023-01-14 23:18:52 +00:00
}: ArticleLayout) {
2023-01-14 19:31:05 +00:00
const pathname = usePathname()
2022-12-06 12:54:34 +00:00
if (isRssFeed) {
return children
}
return (
<>
<Head>
2023-01-14 19:31:05 +00:00
<title>{`${title} - Ryan Freeman`}</title>
<meta name="description" content={description}/>
2022-12-06 12:54:34 +00:00
<meta
property="og:url"
2023-01-14 19:31:05 +00:00
content={`${process.env.NEXT_PUBLIC_SITE_URL}${pathname}`}
2022-12-06 12:54:34 +00:00
/>
<meta
property="og:type"
content="website"
/>
<meta
property="og:title"
2023-01-14 19:31:05 +00:00
content={title}
2022-12-06 12:54:34 +00:00
/>
<meta
property="og:description"
2023-01-14 19:31:05 +00:00
content={description}
2022-12-06 12:54:34 +00:00
/>
2023-01-14 19:31:05 +00:00
{ogImage &&
2022-12-06 12:54:34 +00:00
<>
<meta
property="og:image"
2023-01-14 19:31:05 +00:00
content={ogImage}
2022-12-06 12:54:34 +00:00
/>
<meta
name="twitter:card"
content="summary_large_image"
/>
<meta
name="twitter:image"
2023-01-14 19:31:05 +00:00
content={ogImage}
2022-12-06 12:54:34 +00:00
/>
</>
}
<meta
property="twitter:domain"
content="ryanfreeman.dev"
/>
<meta
property="twitter:url"
2023-01-14 19:31:05 +00:00
content={`${process.env.NEXT_PUBLIC_SITE_URL}${pathname}`}
2022-12-06 12:54:34 +00:00
/>
<meta
name="twitter:title"
2023-01-14 19:31:05 +00:00
content={title}
2022-12-06 12:54:34 +00:00
/>
<meta
name="twitter:description"
2023-01-14 19:31:05 +00:00
content={description}
2022-12-06 12:54:34 +00:00
/>
</Head>
<Container className="mt-16 lg:mt-32">
<div className="xl:relative">
<div className="mx-auto max-w-2xl">
<article>
<header className="flex flex-col">
<h1 className="mt-6 text-4xl font-bold tracking-tight text-zinc-800 dark:text-zinc-100 sm:text-5xl">
2023-01-14 19:31:05 +00:00
{title}
2022-12-06 12:54:34 +00:00
</h1>
2023-01-17 21:24:16 +00:00
<p className="order-first text-base text-zinc-500 dark:text-zinc-400">
<time dateTime={date}>
<span>{formatDate(date)}</span>
</time>
{' '}&middot;{' '}<Views slug={slug}/>
</p>
2022-12-06 12:54:34 +00:00
</header>
<Prose className="mt-8">{children}</Prose>
</article>
</div>
</div>
</Container>
</>
)
}