-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseo.ts
More file actions
48 lines (44 loc) · 1.05 KB
/
seo.ts
File metadata and controls
48 lines (44 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { Metadata } from "next";
import { headers } from "next/headers";
const defaultImage = "/images/pages/home.jpg";
function getSiteUrl(): string {
try {
const host = headers().get("host") ?? "sinfo.org";
const proto = host.startsWith("localhost") ? "http" : "https";
return `${proto}://${host}`;
} catch {
return "https://sinfo.org";
}
}
export function createMetadata({
title,
description,
path = "",
image = defaultImage,
}: {
title: string;
description: string;
path?: string;
image?: string;
}): Metadata {
const siteUrl = getSiteUrl();
const url = `${siteUrl}${path}`;
const absoluteImage = image.startsWith("http") ? image : `${siteUrl}${image}`;
return {
title,
description,
openGraph: {
title: `${title} | SINFO`,
description,
url,
images: [{ url: absoluteImage, alt: title }],
},
twitter: {
card: "summary_large_image",
title: `${title} | SINFO`,
description,
images: [absoluteImage],
},
alternates: { canonical: url },
};
}