Skip to content

Commit afcab01

Browse files
committed
Upgrade og-img and refactor implementation
1 parent 5c59402 commit afcab01

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"eslint-plugin-qwik": "1.1.5",
4747
"gray-matter": "^4.0.3",
4848
"netlify-cli": "^15.0.0",
49-
"og-img": "^0.1.0",
49+
"og-img": "^0.2.0",
5050
"postcss": "^8.4.27",
5151
"prettier": "2.8.8",
5252
"rehype-external-links": "^2.1.0",

website/src/routes/og-image/index.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
import type { RequestHandler } from '@builder.io/qwik-city';
2-
import { ImageResponse, html } from 'og-img';
3-
4-
async function getFontData(fileName: string) {
5-
const resposne = await fetch(
6-
`${import.meta.env.PUBLIC_WEBSITE_URL}/fonts/${fileName}`
7-
);
8-
return resposne.arrayBuffer();
9-
}
2+
import { fetchFont, ImageResponse, html } from 'og-img';
103

114
export const onGet: RequestHandler = async ({ send, url }) => {
125
// Get data from search params
136
const title = url.searchParams.get('title');
147
const description = url.searchParams.get('description');
158
const path = url.searchParams.get('path');
169

10+
// Create font directory URL
11+
const fontDirectory = import.meta.env.PUBLIC_WEBSITE_URL + '/fonts';
12+
1713
// Create Lexend 400 font object
1814
const lexend400 = {
1915
name: 'Lexend',
20-
data: await getFontData('lexend-400.ttf'),
16+
data: await fetchFont(fontDirectory + '/lexend-400.ttf'),
2117
style: 'normal',
2218
weight: 400,
2319
} as const;
2420

2521
// Create Lexend 500 font object
2622
const lexend500 = {
2723
name: 'Lexend',
28-
data: await getFontData('lexend-500.ttf'),
24+
data: await fetchFont(fontDirectory + '/lexend-500.ttf'),
2925
style: 'normal',
3026
weight: 500,
3127
} as const;
3228

3329
// Create Lexend Exa 500 font object
3430
const lexendExa500 = {
3531
name: 'Lexend Exa',
36-
data: await getFontData('lexend-exa-500.ttf'),
32+
data: await fetchFont(fontDirectory + '/lexend-exa-500.ttf'),
3733
style: 'normal',
3834
weight: 500,
3935
} as const;

0 commit comments

Comments
 (0)