feat: add JSON-LD structured data (#260)

- Add author profile to SITE variables
- Add JSON-LD to Layout.astro
This commit is contained in:
David Legrand
2024-07-14 08:06:46 +00:00
committed by GitHub
parent 242729a6fe
commit 8fbb0b4d85
3 changed files with 26 additions and 0 deletions
+24
View File
@@ -8,6 +8,7 @@ const googleSiteVerification = import.meta.env.PUBLIC_GOOGLE_SITE_VERIFICATION;
export interface Props {
title?: string;
author?: string;
profile?: string;
description?: string;
ogImage?: string;
canonicalURL?: string;
@@ -19,6 +20,7 @@ export interface Props {
const {
title = SITE.title,
author = SITE.author,
profile = SITE.profile,
description = SITE.desc,
ogImage = SITE.ogImage,
canonicalURL = new URL(Astro.url.pathname, Astro.site).href,
@@ -31,6 +33,22 @@ const socialImageURL = new URL(
ogImage ?? SITE.ogImage ?? "og.png",
Astro.url.origin
).href;
const structuredData = {
"@context": "https://schema.org",
"@type": "BlogPosting",
headline: `${title}`,
image: `${socialImageURL}`,
datePublished: `${pubDatetime?.toISOString()}`,
...(modDatetime && { dateModified: modDatetime.toISOString() }),
author: [
{
"@type": "Person",
name: `${author}`,
url: `${profile}`,
},
],
};
---
<!doctype html>
@@ -83,6 +101,12 @@ const socialImageURL = new URL(
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={socialImageURL} />
<!-- Google JSON-LD Structured data -->
<script
type="application/ld+json"
set:html={JSON.stringify(structuredData)}
/>
<!-- Google Font -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />