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
+1
View File
@@ -3,6 +3,7 @@ import type { Site, SocialObjects } from "./types";
export const SITE: Site = { export const SITE: Site = {
website: "https://astro-paper.pages.dev/", // replace this with your deployed domain website: "https://astro-paper.pages.dev/", // replace this with your deployed domain
author: "Sat Naing", author: "Sat Naing",
profile: "https://satnaing.dev/",
desc: "A minimal, responsive and SEO-friendly Astro blog theme.", desc: "A minimal, responsive and SEO-friendly Astro blog theme.",
title: "AstroPaper", title: "AstroPaper",
ogImage: "astropaper-og.jpg", ogImage: "astropaper-og.jpg",
+24
View File
@@ -8,6 +8,7 @@ const googleSiteVerification = import.meta.env.PUBLIC_GOOGLE_SITE_VERIFICATION;
export interface Props { export interface Props {
title?: string; title?: string;
author?: string; author?: string;
profile?: string;
description?: string; description?: string;
ogImage?: string; ogImage?: string;
canonicalURL?: string; canonicalURL?: string;
@@ -19,6 +20,7 @@ export interface Props {
const { const {
title = SITE.title, title = SITE.title,
author = SITE.author, author = SITE.author,
profile = SITE.profile,
description = SITE.desc, description = SITE.desc,
ogImage = SITE.ogImage, ogImage = SITE.ogImage,
canonicalURL = new URL(Astro.url.pathname, Astro.site).href, canonicalURL = new URL(Astro.url.pathname, Astro.site).href,
@@ -31,6 +33,22 @@ const socialImageURL = new URL(
ogImage ?? SITE.ogImage ?? "og.png", ogImage ?? SITE.ogImage ?? "og.png",
Astro.url.origin Astro.url.origin
).href; ).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> <!doctype html>
@@ -83,6 +101,12 @@ const socialImageURL = new URL(
<meta property="twitter:description" content={description} /> <meta property="twitter:description" content={description} />
<meta property="twitter:image" content={socialImageURL} /> <meta property="twitter:image" content={socialImageURL} />
<!-- Google JSON-LD Structured data -->
<script
type="application/ld+json"
set:html={JSON.stringify(structuredData)}
/>
<!-- Google Font --> <!-- Google Font -->
<link rel="preconnect" href="https://fonts.googleapis.com" /> <link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
+1
View File
@@ -3,6 +3,7 @@ import type socialIcons from "@assets/socialIcons";
export type Site = { export type Site = {
website: string; website: string;
author: string; author: string;
profile: string;
desc: string; desc: string;
title: string; title: string;
ogImage?: string; ogImage?: string;