Skip to content

Commit 8ea88fd

Browse files
authored
Merge pull request #629 from rishichawda/fix-json-ld-schema
fix json schema
2 parents 61b903d + 95fcd88 commit 8ea88fd

File tree

9 files changed

+623
-432
lines changed

9 files changed

+623
-432
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rishikc.com",
33
"type": "module",
4-
"version": "4.0.4",
4+
"version": "4.0.5",
55
"scripts": {
66
"dev": "astro dev",
77
"build": "astro build",
@@ -15,7 +15,9 @@
1515
"@fontsource-variable/red-hat-text": "^5.2.5",
1616
"@playform/compress": "^0.1.9",
1717
"@unpic/astro": "^1.0.0",
18-
"astro": "^5.5.5"
18+
"astro": "^5.5.5",
19+
"astro-seo-schema": "^5.0.0",
20+
"schema-dts": "^1.1.5"
1921
},
2022
"devDependencies": {
2123
"@astrojs/mdx": "^4.2.2",

src/components/seo.astro

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
11
---
2+
import { Schema } from "astro-seo-schema";
3+
24
let {
3-
page_info: { title, description, image, keywords },
5+
page_info: { title, description, image, keywords },
46
} = Astro.props;
57
68
// Get the site URL for JSON-LD
7-
const canonicalURL = new URL(Astro.url.pathname, Astro.site || 'https://rishikc.com');
9+
const canonicalURL = new URL(
10+
Astro.url.pathname,
11+
Astro.site || "https://rishikc.com",
12+
);
813
---
914

10-
<!-- <head> -->
11-
<meta charset="UTF-8" />
12-
<title>{title}</title>
13-
<meta name="viewport" content="width=device-width" />
14-
<link rel="icon" type="image/svg+xml" href={image} />
15-
<meta name="description" content={description} />
16-
<meta name="image" content={image} />
17-
{keywords ? <meta name="keywords" content={keywords} /> : null}
18-
{/* Open graph / Facebook */}
19-
<meta property="og:title" content={title} />
20-
<meta property="og:site_name" content={title} />
21-
<meta property="og:description" content={description} />
22-
<meta property="og:image" content={image} />
23-
<meta property="og:url" content={Astro.url.pathname} />
24-
{/* Twitter */}
25-
<meta name="twitter:title" content={title} />
26-
<meta name="twitter:description" content={description} />
27-
<meta name="twitter:card" content="summary_large_image" />
28-
<meta name="twitter:image" content={image} />
15+
<meta charset="UTF-8" />
16+
<title>{title}</title>
17+
<meta name="viewport" content="width=device-width" />
18+
<link rel="icon" type="image/svg+xml" href={image} />
19+
<meta name="description" content={description} />
20+
<meta name="image" content={image} />
21+
{keywords ? <meta name="keywords" content={keywords} /> : null}
22+
{/* Open graph / Facebook */}
23+
<meta property="og:title" content={title} />
24+
<meta property="og:site_name" content={title} />
25+
<meta property="og:description" content={description} />
26+
<meta property="og:image" content={image} />
27+
<meta property="og:url" content={Astro.url.pathname} />
28+
{/* Twitter */}
29+
<meta name="twitter:title" content={title} />
30+
<meta name="twitter:description" content={description} />
31+
<meta name="twitter:card" content="summary_large_image" />
32+
<meta name="twitter:image" content={image} />
2933

30-
<!-- WebSite JSON-LD Schema -->
31-
<script type="application/ld+json">
32-
{JSON.stringify({
33-
"@context": "https://schema.org",
34-
"@type": "WebSite",
35-
"name": "Rishi Chawda",
36-
"url": canonicalURL.toString(),
37-
"description": description,
38-
"potentialAction": {
39-
"@type": "SearchAction",
40-
"target": `${canonicalURL.origin}/search?q={search_term_string}`,
41-
"query-input": "required name=search_term_string"
42-
}
43-
})}
44-
</script>
45-
<!-- </head> -->
34+
<!-- WebSite JSON-LD Schema -->
35+
<Schema
36+
item={{
37+
"@context": "https://schema.org",
38+
"@type": "WebSite",
39+
name: "Rishi Chawda",
40+
url: canonicalURL.toString(),
41+
description: description,
42+
potentialAction: {
43+
"@type": "SearchAction",
44+
target: `${canonicalURL.origin}/search?q={search_term_string}`,
45+
"query-input": "required name=search_term_string",
46+
},
47+
}}
48+
/>

src/layouts/article.astro

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
import { Image } from "astro:assets";
3+
import { Schema } from "astro-seo-schema";
34
45
let { content, frontmatter } = Astro.props;
56
@@ -10,39 +11,47 @@ const date = new Date(content.date).toLocaleDateString("en-us", {
1011
});
1112
1213
// Format date for ISO format for JSON-LD
13-
const isoDate = content.date ? new Date(content.date).toISOString() : '';
14-
const articleUrl = new URL(content.path || Astro.url.pathname, Astro.site || 'https://rishikc.com').toString();
15-
const imageUrl = content.hero_image?.src ? new URL(content.hero_image.src, Astro.site || 'https://rishikc.com').toString() : '';
14+
const isoDate = content.date ? new Date(content.date).toISOString() : "";
15+
const articleUrl = new URL(
16+
content.path || Astro.url.pathname,
17+
Astro.site || "https://rishikc.com",
18+
).toString();
19+
const imageUrl = content.hero_image?.src
20+
? new URL(
21+
content.hero_image.src,
22+
Astro.site || "https://rishikc.com",
23+
).toString()
24+
: "";
1625
---
1726

1827
<article class="max-w-[90%] flex flex-col mx-auto items-center pt-10">
1928
<!-- Article JSON-LD Schema -->
20-
<script type="application/ld+json" slot="head">
21-
{JSON.stringify({
29+
<Schema
30+
item={{
2231
"@context": "https://schema.org",
2332
"@type": "BlogPosting",
24-
"headline": content.title,
25-
"description": content.description,
26-
"image": imageUrl,
27-
"datePublished": isoDate,
28-
"dateModified": isoDate,
29-
"author": {
33+
headline: content.title,
34+
description: content.description,
35+
image: imageUrl,
36+
datePublished: isoDate,
37+
dateModified: isoDate,
38+
author: {
3039
"@type": "Person",
31-
"name": "Rishi Chawda",
32-
"url": "https://rishikc.com"
40+
name: "Rishi Chawda",
41+
url: "https://rishikc.com",
3342
},
34-
"publisher": {
43+
publisher: {
3544
"@type": "Person",
36-
"name": "Rishi Chawda",
37-
"url": "https://rishikc.com"
45+
name: "Rishi Chawda",
46+
url: "https://rishikc.com",
3847
},
39-
"mainEntityOfPage": {
48+
mainEntityOfPage: {
4049
"@type": "WebPage",
41-
"@id": articleUrl
50+
"@id": articleUrl,
4251
},
43-
"keywords": content.tags?.join(", ")
44-
})}
45-
</script>
52+
keywords: content.tags?.join(", "),
53+
}}
54+
/>
4655
<div class="inline-flex flex-col justify-start items-center gap-2.5 mb-2">
4756
<h1
4857
transition:name={`${content.path}-title`}
@@ -63,7 +72,7 @@ const imageUrl = content.hero_image?.src ? new URL(content.hero_image.src, Astro
6372
class="justify-start text-black text-center text-sm font-normal font-['Montserrat_Variable'] leading-tight mb-2 mt-7"
6473
>
6574
{date}
66-
</small>
75+
</small>
6776
<div class="w-full md:max-w-[790px] mb-7">
6877
<Image
6978
class="w-full rounded-xl"
@@ -92,7 +101,9 @@ const imageUrl = content.hero_image?.src ? new URL(content.hero_image.src, Astro
92101
</small>
93102
</div>
94103
</div>
95-
<div class="mb-20 font-['Montserrat_Variable'] max-w-full lg:flex lg:flex-row lg:gap-4">
104+
<div
105+
class="mb-20 font-['Montserrat_Variable'] max-w-full lg:flex lg:flex-row lg:gap-4"
106+
>
96107
<slot />
97108
</div>
98109
</article>

0 commit comments

Comments
 (0)