Skip to content

Commit

Permalink
fix: Correctly set blog-set opengraph images
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Jung <alex@unikraft.io>
  • Loading branch information
nderjung committed May 10, 2024
1 parent 8279cde commit 8af72a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
10 changes: 9 additions & 1 deletion src/components/page-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ function PageContainer(props: PageContainerProps) {

return (
<>
<SEO title={title} description={description} />
<SEO title={title} description={description} openGraph={{
title: title,
description: description,
images: [{
url: image,
width: 1200,
height: 630,
}]
}} />
<Grid
w='100vw'
h='100vh'
Expand Down
37 changes: 28 additions & 9 deletions src/components/seo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@ import { NextSeo, NextSeoProps } from 'next-seo'
import React from 'react'
import siteConfig from 'configs/site-config.json'

export type SEOProps = Pick<NextSeoProps, 'title' | 'description'>
export type SEOProps = Pick<NextSeoProps, 'title' | 'description' | 'openGraph'>

const SEO = ({ title, description }: SEOProps) => (
<NextSeo
title={title}
description={description}
openGraph={{ title, description }}
titleTemplate={siteConfig.seo.titleTemplate}
/>
)
const SEO = ({ title, description, openGraph }: SEOProps) => {
if (!openGraph) {
openGraph = {
title,
description,
}
}

if (openGraph && (!openGraph.images || openGraph.images.length === 0)) {
openGraph.images = [
{
url: "/og-image.png",
width: 1200,
height: 630,
},
]
}

return (
<NextSeo
title={title}
description={description}
openGraph={openGraph}
titleTemplate={siteConfig.seo.titleTemplate}
/>
)
}

export default SEO

0 comments on commit 8af72a2

Please sign in to comment.