From 8fbb0b4d85852d6c3f931b94aae90425b678b890 Mon Sep 17 00:00:00 2001
From: David Legrand <1110600+davlgd@users.noreply.github.com>
Date: Sun, 14 Jul 2024 08:06:46 +0000
Subject: [PATCH] feat: add JSON-LD structured data (#260)
- Add author profile to SITE variables
- Add JSON-LD to Layout.astro
---
src/config.ts | 1 +
src/layouts/Layout.astro | 24 ++++++++++++++++++++++++
src/types.ts | 1 +
3 files changed, 26 insertions(+)
diff --git a/src/config.ts b/src/config.ts
index be055eb..fd78e08 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -3,6 +3,7 @@ import type { Site, SocialObjects } from "./types";
export const SITE: Site = {
website: "https://astro-paper.pages.dev/", // replace this with your deployed domain
author: "Sat Naing",
+ profile: "https://satnaing.dev/",
desc: "A minimal, responsive and SEO-friendly Astro blog theme.",
title: "AstroPaper",
ogImage: "astropaper-og.jpg",
diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro
index dfeb001..decf1c7 100644
--- a/src/layouts/Layout.astro
+++ b/src/layouts/Layout.astro
@@ -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}`,
+ },
+ ],
+};
---
@@ -83,6 +101,12 @@ const socialImageURL = new URL(
+
+
+
diff --git a/src/types.ts b/src/types.ts
index 72ba2f0..f9eaf38 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -3,6 +3,7 @@ import type socialIcons from "@assets/socialIcons";
export type Site = {
website: string;
author: string;
+ profile: string;
desc: string;
title: string;
ogImage?: string;