-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathArtworkMeta.tsx
More file actions
95 lines (83 loc) · 2.8 KB
/
ArtworkMeta.tsx
File metadata and controls
95 lines (83 loc) · 2.8 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
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
import { ArtworkStructuredData } from "Apps/Artwork/Components/ArtworkStructuredData"
import { useRouter } from "System/Hooks/useRouter"
import { getENV } from "Utils/getENV"
import type { ArtworkMeta_artwork$key } from "__generated__/ArtworkMeta_artwork.graphql"
import { Suspense } from "react"
import { Link, Meta, Title } from "react-head"
import { graphql, useFragment } from "react-relay"
import { ArtworkChatBubbleFragmentContainer } from "./ArtworkChatBubble"
interface ArtworkMetaProps {
artwork: ArtworkMeta_artwork$key
}
export const ArtworkMeta: React.FC<
React.PropsWithChildren<ArtworkMetaProps>
> = ({ artwork }) => {
const { match } = useRouter()
const data = useFragment(artworkMetaFragment, artwork)
const pathname = match.location.pathname
const imageURL = data.metaImage?.resized?.url
const addNoIndex = data.isUnlisted || pathname.includes(data?.internalID) // a previously private artwork URL
return (
<>
<Title>{data.meta?.title}</Title>
<Meta name="description" content={data.meta?.description} />
<Link rel="canonical" href={`${getENV("APP_URL")}${data.href}`} />
<Meta
property="twitter:description"
content={data.meta?.longDescription}
/>
<Meta property="og:title" content={data.meta?.title} />
<Meta property="og:description" content={data.meta?.description} />
<Meta property="og:url" content={`${getENV("APP_URL")}${data.href}`} />
<Meta
property="og:type"
content={`${getENV("FACEBOOK_APP_NAMESPACE")}:artwork`}
/>
{/* Images */}
{imageURL && <Meta name="thumbnail" content={imageURL} />}
{data.isShareable && imageURL ? (
<>
<Meta property="twitter:card" content="summary_large_image" />
<Meta property="og:image" content={imageURL} />
<Meta
property="og:image:width"
content={data.metaImage?.resized?.width}
/>
<Meta
property="og:image:height"
content={data.metaImage?.resized?.height}
/>
</>
) : (
<Meta property="twitter:card" content="summary" />
)}
{addNoIndex && <Meta name="robots" content="noindex, follow" />}
<ArtworkChatBubbleFragmentContainer artwork={data} />
<Suspense fallback={null}>
<ArtworkStructuredData id={data.slug} />
</Suspense>
</>
)
}
const artworkMetaFragment = graphql`
fragment ArtworkMeta_artwork on Artwork {
...ArtworkChatBubble_artwork
slug
href
internalID
isShareable
isUnlisted
metaImage: image {
resized(width: 640, height: 640, version: ["large", "medium", "tall"]) {
width
height
url
}
}
meta {
title
description(limit: 155)
longDescription: description(limit: 200)
}
}
`