107 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-01-10 17:35:37 +08:00
import { NextSeo, ArticleJsonLd } from 'next-seo'
2021-01-09 17:50:45 +08:00
import siteMetadata from '@/data/siteMetadata'
2021-01-10 17:35:37 +08:00
export const SEO = {
2021-01-09 17:50:45 +08:00
title: siteMetadata.title,
description: siteMetadata.description,
openGraph: {
type: 'website',
locale: siteMetadata.language,
url: siteMetadata.siteUrl,
title: siteMetadata.title,
description: siteMetadata.description,
images: [
{
2021-01-10 17:50:44 +08:00
url: `${siteMetadata.siteUrl}${siteMetadata.socialBanner}`,
2021-01-09 17:50:45 +08:00
alt: siteMetadata.title,
2021-01-10 17:50:44 +08:00
width: 1200,
height: 600,
2021-01-09 17:50:45 +08:00
},
],
},
twitter: {
handle: siteMetadata.twitter,
site: siteMetadata.twitter,
cardType: 'summary_large_image',
},
2021-01-10 18:34:30 +08:00
additionalMetaTags: [
{
2021-01-10 18:52:30 +08:00
name: 'author',
2021-01-10 18:34:30 +08:00
content: siteMetadata.author,
},
],
2021-01-09 17:50:45 +08:00
}
2021-01-10 17:35:37 +08:00
export const PageSeo = ({ title, description, url }) => {
return (
2021-01-13 22:39:56 +08:00
<NextSeo
title={`${title} ${siteMetadata.title}`}
description={description}
canonical={url}
openGraph={{
url,
title,
description,
}}
/>
2021-01-10 17:35:37 +08:00
)
}
export const BlogSeo = ({ title, summary, date, lastmod, url, tags, images = [] }) => {
2021-01-10 17:35:37 +08:00
const publishedAt = new Date(date).toISOString()
const modifiedAt = new Date(lastmod || date).toISOString()
let imagesArr =
2021-01-18 23:41:48 +08:00
images.length === 0
? [siteMetadata.socialBanner]
: typeof images === 'string'
2021-01-18 23:47:17 +08:00
? [images]
: images
const featuredImages = imagesArr.map((img) => {
return {
url: `${siteMetadata.siteUrl}${img}`,
alt: title,
}
})
2021-01-10 17:35:37 +08:00
return (
<>
<NextSeo
title={`${title} ${siteMetadata.title}`}
description={summary}
canonical={url}
openGraph={{
type: 'article',
article: {
publishedTime: publishedAt,
modifiedTime: modifiedAt,
2021-01-10 18:20:53 +08:00
authors: [`${siteMetadata.siteUrl}/about`],
tags,
2021-01-10 17:35:37 +08:00
},
url,
title,
description: summary,
images: featuredImages,
2021-01-10 17:35:37 +08:00
}}
additionalMetaTags={[
{
name: 'twitter:image',
content: featuredImages[0],
},
]}
2021-01-10 17:35:37 +08:00
/>
<ArticleJsonLd
authorName={siteMetadata.author}
dateModified={publishedAt}
datePublished={modifiedAt}
2021-01-10 17:35:37 +08:00
description={summary}
images={featuredImages}
2021-01-10 17:35:37 +08:00
publisherLogo="/static/favicons/android-chrome-96x96.png"
publisherName={siteMetadata.author}
title={title}
url={url}
/>
</>
)
}