Skip to content

Commit c8d0b79

Browse files
HoomanDgtldharamveergitOlanetsoft
authored
feat: SEO optimization, add sitemap link to footer and update robots.txt with meta dire… (#1369)
Co-authored-by: Dharamveer singh <[email protected]> Co-authored-by: Idris Olubisi <[email protected]>
1 parent fe24fdc commit c8d0b79

File tree

5 files changed

+113
-8
lines changed

5 files changed

+113
-8
lines changed

astro.config.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export default defineConfig({
2121
}),
2222
react(),
2323
mdx(),
24-
sitemap(),
24+
sitemap({
25+
priority: 0.9,
26+
changefreq: "daily",
27+
lastmod: new Date(),
28+
}),
2529
tailwind(),
2630
partytown({
2731
config: {

public/robots.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
User-agent: *
22
Allow: /
3-
Sitemap: https://docs.axelar.dev/sitemap-0.xml
3+
Sitemap: https://docs.axelar.dev/sitemap-0.xml
4+
5+
6+
# Meta directives
7+
INDEX, FOLLOW, MAX-IMAGE-PREVIEW:LARGE, MAX-SNIPPET:-1, MAX-VIDEO-PREVIEW:-1

src/components/footer/footer.astro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ const links = [
7474
title: "Terms of Use",
7575
href: "/terms-of-use/",
7676
},
77+
{
78+
title: "Sitemap",
79+
href: "/sitemap-0.xml",
80+
},
7781
],
7882
},
7983
];

src/layouts/MainLayout.astro

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type Props = {
1212
hidden?: boolean;
1313
notSidebar?: boolean;
1414
className?: string;
15+
publishDate?: string;
16+
modifiedDate?: string;
1517
};
1618
1719
const {
@@ -21,11 +23,11 @@ const {
2123
hidden,
2224
notSidebar,
2325
className,
26+
publishDate = new Date().toISOString(),
27+
modifiedDate = new Date().toISOString(),
2428
} = Astro.props;
2529
26-
const shownTitle = title
27-
? title + ` | Axelar Documentation`
28-
: "Axelar Documentation";
30+
const shownTitle = title ? title : "Axelar Documentation";
2931
const shownDescription =
3032
description ||
3133
"The Axelar Documentation tells you how to get started and be successful using Axelar. Axelar allows developers to build interchain dApps that connect to any blockchain. ";
@@ -70,7 +72,58 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);
7072
<meta content="website" property="og:type" />
7173
<meta content="summary_large_image" name="twitter:card" />
7274
<meta content="width=device-width, initial-scale=1" name="viewport" />
73-
{hidden && <meta content="noindex" name="robots" />}
75+
{
76+
hidden ? (
77+
<meta content="noindex" name="robots" />
78+
) : (
79+
<meta
80+
name="robots"
81+
content="INDEX, FOLLOW, MAX-IMAGE-PREVIEW:LARGE, MAX-SNIPPET:-1, MAX-VIDEO-PREVIEW:-1"
82+
/>
83+
)
84+
}
85+
86+
{
87+
publishDate && (
88+
<meta property="article:published_time" content={publishDate} />
89+
)
90+
}
91+
{
92+
modifiedDate && (
93+
<meta property="article:modified_time" content={modifiedDate} />
94+
)
95+
}
96+
97+
<script
98+
type="application/ld+json"
99+
set:html={JSON.stringify({
100+
"@context": "https://schema.org",
101+
"@type": "Article",
102+
mainEntityOfPage: {
103+
"@type": "WebPage",
104+
"@id": canonicalURL.toString(),
105+
},
106+
headline: shownTitle,
107+
description: shownDescription,
108+
image: new URL(image, Astro.url).toString(),
109+
author: {
110+
"@type": "Organization",
111+
name: "Axelar",
112+
url: "https://docs.axelar.dev",
113+
},
114+
publisher: {
115+
"@type": "Organization",
116+
name: "Axelar",
117+
logo: {
118+
"@type": "ImageObject",
119+
url: "https://docs.axelar.dev/images/Axelar%20Logo%20Full%[email protected]",
120+
},
121+
},
122+
datePublished: publishDate,
123+
dateModified: modifiedDate || publishDate,
124+
})}
125+
/>
126+
74127
<link
75128
rel="sitemap"
76129
type="application/xml"
@@ -163,7 +216,7 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);
163216
localStorage.setItem("theme", isDark ? "dark" : "light");
164217
document.documentElement.setAttribute(
165218
"data-theme",
166-
isDark ? "vitesse-dark" : "light-plus"
219+
isDark ? "vitesse-dark" : "light-plus",
167220
);
168221
};
169222

src/pages/[...slug].astro

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,49 @@ const { doc } = Astro.props;
2424
2525
const pathname = Astro.url.pathname;
2626
const { Content, headings } = await doc.render();
27+
28+
// Extract first image from content
29+
const extractFirstImage = (content: string) => {
30+
const imageRegex = /!\[.*?\]\((.*?)\)/;
31+
const match = content.match(imageRegex);
32+
return match ? match[1] : undefined;
33+
};
34+
35+
const firstImage = extractFirstImage(doc.body);
2736
---
2837

29-
<MainLayout title={headings.find((h) => h.depth === 1)?.text}>
38+
<MainLayout
39+
image={firstImage}
40+
title={headings.find((h) => h.depth === 1)?.text}
41+
description={(() => {
42+
// Get the first h2 heading
43+
const h2Heading = headings.find((h) => h.depth === 2)?.text;
44+
// Get the first paragraph from the raw content and clean it
45+
const firstParagraph = doc.body
46+
?.split("\n\n")[0]
47+
?.replace(/^#.*\n/, "") // Remove title
48+
?.replace(/```[\s\S]*?```/g, "") // Remove code blocks
49+
?.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") // Convert markdown links to plain text
50+
?.replace(/#/g, "") // Remove all # characters
51+
?.replace(/\*\*/g, "") // Remove bold
52+
?.replace(/\*/g, "") // Remove italic
53+
?.replace(/`/g, "") // Remove inline code
54+
?.replace(/\n/g, " ") // Replace newlines with spaces
55+
?.replace(/\s+/g, " ") // Replace multiple spaces with single space
56+
?.trim();
57+
58+
// Limit description length to 160 characters
59+
const maxLength = 160;
60+
const combined =
61+
firstParagraph && h2Heading
62+
? `${firstParagraph} ${h2Heading}`
63+
: h2Heading || firstParagraph || "";
64+
65+
return combined.length > maxLength
66+
? combined.substring(0, maxLength - 3) + "..."
67+
: combined;
68+
})()}
69+
>
3070
<div class="grid grid-cols-1 lg:grid-cols-12 bg-[#FFFFFF] dark:bg-background">
3171
<WorldMap className="lg:col-span-9 2xl:col-span-10 w-full flex-1 ">
3272
<div class="min-h-[90dvh] sub-container pb-20 py-20 flex flex-col gap-10">

0 commit comments

Comments
 (0)