src/layouts/Base/SchemaOrg.astro
---
import config from '@config/blog.config'
export type Props = {
title: string
url: string
image: string
description: string
datePublished?: string
dateModified?: string
}
const { title, url, image, description, datePublished, dateModified } =
Astro.props
const { siteUrl, siteTitle, author } = config
const schema = datePublished
? {
'@context': 'http://schema.org',
'@type': 'BlogPosting',
author: {
'@type': 'Person',
name: author.name,
url: author.url
},
publisher: {
'@type': 'Organization',
name: author.name
},
url,
headline: title,
image: {
'@type': 'ImageObject',
url: image
},
description,
datePublished,
dateModified: dateModified || datePublished,
mainEntityOfPage: {
'@type': 'Blog',
'@id': siteUrl
}
}
: {
'@context': 'http://schema.org',
'@type': 'Blog',
url: siteUrl,
name: siteTitle
}
---
<script
type="application/ld+json"
set:html={JSON.stringify(schema)}
is:inline
/>