forked from transitive-bullshit/nextjs-notion-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPageHead.tsx
102 lines (89 loc) · 2.77 KB
/
PageHead.tsx
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import * as React from 'react'
import Head from 'next/head'
import * as config from '@/lib/config'
import * as types from '@/lib/types'
import { getSocialImageUrl } from '@/lib/get-social-image-url'
export const PageHead: React.FC<
types.PageProps & {
title?: string
description?: string
image?: string
url?: string
}
> = ({ site, title, description, pageId, image, url }) => {
const rssFeedUrl = `${config.host}/feed`
title = title ?? site?.name
description = description ?? site?.description
const socialImageUrl = getSocialImageUrl(pageId) || image
return (
<Head>
<meta charSet='utf-8' />
<meta httpEquiv='Content-Type' content='text/html; charset=utf-8' />
<meta
name='viewport'
content='width=device-width, initial-scale=1, shrink-to-fit=no'
/>
<meta name='robots' content='index,follow' />
<meta property='og:type' content='website' />
{site && (
<>
<meta property='og:site_name' content={site.name} />
<meta property='twitter:domain' content={site.domain} />
</>
)}
<meta name='theme-color' content='#EB625A' />
<meta property='og:type' content='website' />
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${config.GAId}`}
/>
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${config.GAId}', {
page_path: window.location.pathname,
});
`
}}
/>
{config.twitter && (
<meta name='twitter:creator' content={`@${config.twitter}`} />
)}
{description && (
<>
<meta name='description' content={description} />
<meta property='og:description' content={description} />
<meta name='twitter:description' content={description} />
</>
)}
{socialImageUrl ? (
<>
<meta name='twitter:card' content='summary_large_image' />
<meta name='twitter:image' content={socialImageUrl} />
<meta property='og:image' content={socialImageUrl} />
</>
) : (
<meta name='twitter:card' content='summary' />
)}
{url && (
<>
<link rel='canonical' href={url} />
<meta property='og:url' content={url} />
<meta property='twitter:url' content={url} />
</>
)}
<link
rel='alternate'
type='application/rss+xml'
href={rssFeedUrl}
title={site?.name}
/>
<meta property='og:title' content={title} />
<meta name='twitter:title' content={title} />
<title>{title}</title>
</Head>
)
}