-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMetaHeader.tsx
More file actions
52 lines (48 loc) · 1.47 KB
/
MetaHeader.tsx
File metadata and controls
52 lines (48 loc) · 1.47 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
49
50
51
52
import React from "react";
import Head from "next/head";
type MetaHeaderProps = {
title?: string;
description?: string;
image?: string;
twitterCard?: string;
children?: React.ReactNode;
};
// Images must have an absolute path to work properly on Twitter.
// We try to get it dynamically from Vercel, but we default to relative path.
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}/` : "/";
export const MetaHeader = ({
title = "SkillLink",
description = "Built with love",
image = "thumbnail.jpg",
twitterCard = "summary_large_image",
children,
}: MetaHeaderProps) => {
const imageUrl = baseUrl + image;
return (
<Head>
{title && (
<>
<title>{title}</title>
<meta property="og:title" content={title} />
<meta name="twitter:title" content={title} />
</>
)}
{description && (
<>
<meta name="description" content={description} />
<meta property="og:description" content={description} />
<meta name="twitter:description" content={description} />
</>
)}
{image && (
<>
<meta property="og:image" content={imageUrl} />
<meta name="twitter:image" content={imageUrl} />
</>
)}
{twitterCard && <meta name="twitter:card" content={twitterCard} />}
<link rel="icon" type="image/png" sizes="32x32" href="/favicon.png" />
{children}
</Head>
);
};