-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba3c834
commit 6b7f0bf
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
import { getEntry } from 'astro:content'; | ||
interface Props { | ||
headline: string; | ||
description: string; | ||
publishDate: Date; | ||
keywords: string[]; | ||
articleSection: string; | ||
author: { | ||
nameTC: string; | ||
url: string; | ||
} | undefined; | ||
} | ||
const { headline, description, publishDate, keywords, author, articleSection } = Astro.props; | ||
const mySite = await getEntry('character', 'my-site'); | ||
const me = await getEntry('character', 'me'); | ||
const defaultOrganization = { | ||
"@type": "Organization", | ||
"name": mySite.data.nameTC, | ||
"url": mySite.data.social.url | ||
} | ||
const postAuthor = { | ||
"author": { | ||
"@type": "Person", | ||
"name": author?.nameTC, | ||
"url": author?.url, | ||
} | ||
} | ||
const defaultAuthor = { | ||
"author": { | ||
"@type": "Person", | ||
"name": me.data.nameTC, | ||
"url": me.data.social.url, | ||
} | ||
} | ||
const postSchema = { | ||
"@context": "https://schema.org", | ||
"@type": "BlogPosting", | ||
"url": Astro.url, | ||
"headline": headline, | ||
"description": description, | ||
"keywords": keywords, | ||
/* the schema expects is ISO 8601 format. For Date that is yyyy-MM-dd */ | ||
"datePublished": publishDate.toISOString().substring(0, 10), | ||
"publisher": defaultOrganization, | ||
"articleSection": articleSection, | ||
...(author ? postAuthor : defaultAuthor), | ||
}; | ||
--- | ||
|
||
<script type="application/ld+json" set:html={JSON.stringify(postSchema)} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters