Skip to content

Commit eb736d9

Browse files
committed
Add open graph image to website
1 parent a5406f1 commit eb736d9

File tree

6 files changed

+306
-24
lines changed

6 files changed

+306
-24
lines changed

pnpm-lock.yaml

+122
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@types/node": "^20.4.2",
4040
"@typescript-eslint/eslint-plugin": "^6.1.0",
4141
"@typescript-eslint/parser": "^6.1.0",
42+
"@vercel/og": "^0.6.2",
4243
"autoprefixer": "^10.4.14",
4344
"dotenv": "^16.3.1",
4445
"eslint": "^8.45.0",

website/src/components/Head.tsx

+19-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export const Head = component$(() => {
1212

1313
return (
1414
<head>
15-
<title>{head.title}</title>
15+
<title>
16+
{location.url.pathname === '/' ? head.title : `${head.title} | Valibot`}
17+
</title>
1618

1719
<meta charSet="utf-8" />
1820
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@@ -27,6 +29,20 @@ export const Head = component$(() => {
2729
<link rel="apple-touch-icon" sizes="180x180" href="/icon-180px.jpg" />
2830
<link rel="manifest" href="/manifest.json" />
2931

32+
<meta
33+
property="og:image"
34+
content={
35+
location.url.pathname === '/'
36+
? '/og-image'
37+
: `/og-image?title=${encodeURIComponent(
38+
head.title
39+
)}&description=${encodeURIComponent(
40+
head.meta.find((item) => item.name === 'description')
41+
?.content || ''
42+
)}`
43+
}
44+
/>
45+
3046
<script
3147
async
3248
src="https://umami.valibot.dev/script.js"
@@ -41,20 +57,8 @@ export const Head = component$(() => {
4157
<script dangerouslySetInnerHTML="document.documentElement.classList.remove('dark')" />
4258
)}
4359

44-
{[...head.meta, ...(head.frontmatter.meta || [])].map(
45-
({ key, ...props }) => (
46-
<meta key={key} {...props} />
47-
)
48-
)}
49-
50-
{/* TODO: Check if we really need this code */}
51-
{head.links.map(({ key, ...props }) => (
52-
<link key={key} {...props} />
53-
))}
54-
55-
{/* TODO: Check if we really need this code */}
56-
{head.styles.map(({ key, style, ...props }) => (
57-
<style key={key} {...props} dangerouslySetInnerHTML={style} />
60+
{head.meta.map(({ key, ...props }) => (
61+
<meta key={key} {...props} />
5862
))}
5963
</head>
6064
);

website/src/routes/layout.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import { component$, Slot, useSignal } from '@builder.io/qwik';
2-
import { type DocumentHead } from '@builder.io/qwik-city';
32
import { DocSearch, Footer, Header, RoutingIndicator } from '~/components';
43

5-
export const head: DocumentHead = (request) => ({
6-
// Add name of site to title of subpages
7-
title:
8-
request.url.pathname === '/'
9-
? request.head.title
10-
: `${request.head.title} | Valibot`,
11-
});
12-
134
export default component$(() => {
145
// Use search open signal
156
const searchOpen = useSignal(false);

0 commit comments

Comments
 (0)