Skip to content

Commit 985d043

Browse files
IestynGagehasparus
andauthored
Add head properties needed for twitter card (#2206)
## Description Occasioanlly it didn't seem to like the "normal" open graph properties when playing around with a personal website, perhaps a follow up PR is needed to re-declare the og properties to work (e.g. `twitter:description`)? Although it could also be a issue with twitter/x caching things. Added a twitter card type + set the image using a full path. The are two types of cards summary <img width="691" height="279" alt="Image" src="https://github.com/user-attachments/assets/451fe636-127c-4880-a8e1-6cd27462b8f4" /> or summary_large_image <img width="612" height="417" alt="Screenshot 2025-10-25 at 18 51 48" src="https://github.com/user-attachments/assets/f20b4474-b560-4e96-b55f-e6622c85b30a" /> I went with the first one. The image doesn't look correctly formatted however after #1963 it might just resolve itself... Closes #2196 ### Supplementary material * https://cards-dev.x.com/validator * https://developer.x.com/en/docs/x-for-websites/cards/overview/markup --------- Co-authored-by: Piotr Monwid-Olechnowicz <hasparus@gmail.com>
1 parent a367f08 commit 985d043

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

public/img/og-logo.png

45.8 KB
Loading

theme.config.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const graphQLLogo = (
1212
<GraphQLWordmarkLogo className="nextra-logo h-6" title="GraphQL" />
1313
)
1414

15+
const absoluteUrl =
16+
`https://${process.env.VERCEL_URL}` ||
17+
process.env.__NEXT_PRIVATE_ORIGIN ||
18+
"http://localhost:3000"
19+
1520
export default {
1621
backgroundColor: {
1722
light: "251,251,249",
@@ -42,9 +47,24 @@ export default {
4247
</>
4348
)}
4449
{canonical && <link rel="canonical" href={canonical} />}
45-
{image && <meta name="og:image" content={image} />}
46-
<meta property="og:image" content="/img/og-image.png" />
50+
4751
<meta property="twitter:site" content="@graphql" />
52+
53+
{image ? (
54+
<>
55+
{/* if there is an OG image, we show a bigger card */}
56+
<meta property="og:image" content={image} />
57+
<meta name="twitter:card" content="summary_large_image" />
58+
</>
59+
) : (
60+
<>
61+
<meta
62+
property="og:image"
63+
content={`${absoluteUrl}/img/og-logo.png`}
64+
/>
65+
<meta name="twitter:card" content="summary" />
66+
</>
67+
)}
4868
</>
4969
)
5070
},

0 commit comments

Comments
 (0)