Skip to content

Commit 86f340e

Browse files
amaan-bhatinehagup
andauthored
feat: add json-ld schema to docs homepage (#739)
Signed-off-by: amaan-bhati <amaanbhati49@gmail.com> Co-authored-by: Neha Gupta <gneha21@yahoo.in>
1 parent 502029a commit 86f340e

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

src/pages/index.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,81 @@
11
import React from "react";
22
import Layout from "@theme/Layout";
3+
import Head from "@docusaurus/Head";
34
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
45
import {Community, KeployCloud, Resources, QuickStart} from "../components";
56
import {Products} from "../components/Product";
67
//import {Intro} from "../components";
78
export default function Home() {
89
const context = useDocusaurusContext();
910
const {siteConfig = {}} = context;
11+
const toAbsoluteUrl = (baseUrl, url) => {
12+
if (!url) {
13+
return null;
14+
}
15+
if (url.startsWith("http://") || url.startsWith("https://")) {
16+
return url;
17+
}
18+
const trimmedBase = baseUrl?.replace(/\/$/, "") ?? "";
19+
const normalizedPath = url.startsWith("/") ? url : `/${url}`;
20+
return `${trimmedBase}${normalizedPath}`;
21+
};
22+
const docsUrl = toAbsoluteUrl(siteConfig.url, siteConfig.baseUrl);
23+
const breadcrumbSchema =
24+
docsUrl && siteConfig.url
25+
? {
26+
"@context": "https://schema.org",
27+
"@type": "BreadcrumbList",
28+
itemListElement: [
29+
{
30+
"@type": "ListItem",
31+
position: 1,
32+
name: "Home",
33+
item: siteConfig.url,
34+
},
35+
{
36+
"@type": "ListItem",
37+
position: 2,
38+
name: "Docs",
39+
item: docsUrl,
40+
},
41+
],
42+
}
43+
: null;
44+
const articleSchema =
45+
docsUrl && siteConfig.title
46+
? {
47+
"@context": "https://schema.org",
48+
"@type": "Article",
49+
headline: siteConfig.title,
50+
description: siteConfig.tagline,
51+
mainEntityOfPage: {
52+
"@type": "WebPage",
53+
"@id": docsUrl,
54+
},
55+
publisher: {
56+
"@type": "Organization",
57+
name: "Keploy",
58+
logo: {
59+
"@type": "ImageObject",
60+
url: "https://keploy.io/docs/img/favicon.png",
61+
},
62+
},
63+
}
64+
: null;
1065
return (
1166
<div className="main">
67+
<Head>
68+
{breadcrumbSchema && (
69+
<script type="application/ld+json">
70+
{JSON.stringify(breadcrumbSchema)}
71+
</script>
72+
)}
73+
{articleSchema && (
74+
<script type="application/ld+json">
75+
{JSON.stringify(articleSchema)}
76+
</script>
77+
)}
78+
</Head>
1279
<Layout
1380
className="mx-auto my-2 w-full max-w-screen-lg px-8 shadow-none"
1481
title={`${siteConfig.title}`}

0 commit comments

Comments
 (0)