Skip to content

Commit d87eece

Browse files
lucksptFrancisca105
authored andcommitted
feat(seo): speakers seo
1 parent d297bb3 commit d87eece

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/app/layout.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export const metadata: Metadata = {
4343
images: [
4444
{
4545
url: "/images/pages/home.jpg",
46-
width: 1200,
47-
height: 630,
4846
alt: "SINFO — Portugal's Biggest Free Tech Conference",
4947
},
5048
],

src/app/speakers/[id]/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
2525
? speaker.description.slice(0, 160)
2626
: `${speaker.name} — speaker at SINFO, Portugal's biggest free tech conference.`;
2727

28+
const seoImageUrl = `https://static.sinfo.org/website/33-sinfo/seo/speakers/${params.id}.jpg`;
29+
const seoImageExists = await fetch(seoImageUrl, { method: "HEAD" })
30+
.then((r) => r.ok)
31+
.catch(() => false);
32+
const image = seoImageExists ? seoImageUrl : "/images/pages/home.jpg";
33+
2834
return createMetadata({
2935
title: speaker.name,
3036
description,
3137
path: `/speakers/${params.id}`,
32-
image: speaker.img ?? "/images/pages/current-speakers.jpg",
38+
image,
3339
});
3440
}
3541

src/lib/seo.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import type { Metadata } from "next";
2+
import { headers } from "next/headers";
23

3-
const siteUrl = "https://sinfo.org";
4-
const defaultImage = "/images/pages/home.png";
4+
const defaultImage = "/images/pages/home.jpg";
5+
6+
function getSiteUrl(): string {
7+
try {
8+
const host = headers().get("host") ?? "sinfo.org";
9+
const proto = host.startsWith("localhost") ? "http" : "https";
10+
return `${proto}://${host}`;
11+
} catch {
12+
return "https://sinfo.org";
13+
}
14+
}
515

616
export function createMetadata({
717
title,
@@ -14,7 +24,9 @@ export function createMetadata({
1424
path?: string;
1525
image?: string;
1626
}): Metadata {
27+
const siteUrl = getSiteUrl();
1728
const url = `${siteUrl}${path}`;
29+
const absoluteImage = image.startsWith("http") ? image : `${siteUrl}${image}`;
1830

1931
return {
2032
title,
@@ -23,13 +35,13 @@ export function createMetadata({
2335
title: `${title} | SINFO`,
2436
description,
2537
url,
26-
images: [{ url: image, width: 1200, height: 630, alt: title }],
38+
images: [{ url: absoluteImage, alt: title }],
2739
},
2840
twitter: {
2941
card: "summary_large_image",
3042
title: `${title} | SINFO`,
3143
description,
32-
images: [image],
44+
images: [absoluteImage],
3345
},
3446
alternates: { canonical: url },
3547
};

0 commit comments

Comments
 (0)