Skip to content

Commit 76321ca

Browse files
authored
feat: add Open Graph image mapping for services to enhance SEO and sharing
1 parent 297b49a commit 76321ca

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/layouts/ServiceLayout.astro

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ type Props = {
3535
const siteUrl = buildSiteUrl(Astro.site);
3636
const currentYear = new Date().getFullYear();
3737
38+
const SERVICE_OG_MAP: Record<string, string> = {
39+
"ai-automation": `${siteUrl}/og-service-ai.png`,
40+
"technical-seo": `${siteUrl}/og-service-seo.png`,
41+
"full-stack-web-development": `${siteUrl}/og-service-web.png`,
42+
};
43+
3844
const {
3945
title,
4046
description,
@@ -45,21 +51,28 @@ const {
4551
serviceName,
4652
serviceDescription,
4753
keywords = [],
48-
ogImage = new URL("/og-services.png", siteUrl).toString(),
54+
ogImage,
4955
faqs = [],
5056
publishedTime,
5157
modifiedTime,
5258
} = Astro.props as Props;
5359
5460
const canonicalUrl = normalizeCanonicalUrl(Astro.url.pathname, siteUrl);
55-
const finalOgImage = ogImage.startsWith("http")
56-
? ogImage
57-
: new URL(ogImage, siteUrl).toString();
5861
5962
const currentServiceSlug = Astro.url.pathname
6063
.replace(/^\/services\//, "")
6164
.replace(/\/$/, "");
6265
66+
const serviceSlug = currentServiceSlug;
67+
68+
const finalOgImage =
69+
SERVICE_OG_MAP[serviceSlug] ??
70+
(ogImage
71+
? ogImage.startsWith("http")
72+
? ogImage
73+
: new URL(ogImage, siteUrl).toString()
74+
: `${siteUrl}/og-ai-growth-engineer.png`);
75+
6376
const relatedServices = serviceCrossLinks
6477
.filter((service) => service.slug !== currentServiceSlug)
6578
.slice(0, 3);

0 commit comments

Comments
 (0)