Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

Seo.js

80 lines2.2 KB

1import React from 'react'
2import Head from 'next/head'
3import { withRouter } from 'next/router'
4​
5const ogImage = require('images/og-dark.png?url')
6const favicon = require('images/favicon.png?url')
7​
8export const Seo = withRouter(
9 ({ title, description, image = ogImage, router, children }) => (
10 <Head>
11 {/* DEFAULT */}
12​
13 {title != undefined && (
14 <title key="title">{title} | React Location | TanStack</title>
15 )}
16 {description != undefined && (
17 <meta name="description" key="description" content={description} />
18 )}
19 <link rel="icon" type="image/x-icon" href={favicon} />
20 <link rel="apple-touch-icon" href={favicon} />
21​
22 {/* OPEN GRAPH */}
23 <meta property="og:type" key="og:type" content="website" />
24 <meta
25 property="og:url"
26 key="og:url"
27 content={`https://react-location.tanstack.com${router.pathname}`}
28 />
29 {title != undefined && (
30 <meta property="og:title" content={title} key="og:title" />
31 )}
32 {description != undefined && (
33 <meta
34 property="og:description"
35 key="og:description"
36 content={description}
37 />
38 )}
39 {image != undefined && (
40 <meta
41 property="og:image"
42 key="og:image"
43 content={`https://react-location.tanstack.com${image}`}
44 />
45 )}
46​
47 {/* TWITTER */}
48 <meta
49 name="twitter:card"
50 key="twitter:card"
51 content="summary_large_image"
52 />
53 <meta name="twitter:site" key="twitter:site" content="@tan_stack" />
54 <meta
55 name="twitter:creator"
56 key="twitter:creator"
57 content="@tannerlinsley"
58 />
59 {title != undefined && (
60 <meta name="twitter:title" key="twitter:title" content={title} />
61 )}
62 {description != undefined && (
63 <meta
64 name="twitter:description"
65 key="twitter:description"
66 content={description}
67 />
68 )}
69 {image != undefined && (
70 <meta
71 name="twitter:image"
72 key="twitter:image"
73 content={`https://react-location.tanstack.com${image}`}
74 />
75 )}
76​
77 {children}
78 </Head>
79 ),