Skip to content

Commit 5c20425

Browse files
Fix OG Images (#156)
1 parent d30afc2 commit 5c20425

File tree

9 files changed

+236
-222
lines changed

9 files changed

+236
-222
lines changed
File renamed without changes.

app/routes/img.$slug/route.tsx

Lines changed: 2 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,10 @@
11
import { type LoaderFunctionArgs } from "@remix-run/node";
2-
import satori from "satori";
32
import svg2img from "svg2img";
4-
import { getDataFromParams, getFont } from "./utils.server";
5-
6-
// Big thanks goes to Jacob Paris' blog outlining how to set this up
7-
// https://www.jacobparis.com/content/remix-og
8-
9-
let primaryTextColor = "#ffffff";
10-
let secondaryTextColor = "#d0d0d0";
11-
12-
let primaryFont = "Inter";
13-
let titleFont = "Inter";
3+
import { createOgImageSVG } from "./utils.server";
144

155
export async function loader({ request }: LoaderFunctionArgs) {
16-
let requestUrl = new URL(request.url);
17-
let searchParams = new URLSearchParams(requestUrl.search);
18-
let siteUrl = requestUrl.protocol + "//" + requestUrl.host;
19-
20-
let { title, displayDate, authors } = getDataFromParams(
21-
siteUrl,
22-
searchParams,
23-
);
24-
25-
const svg = await satori(
26-
<div
27-
style={{
28-
display: "flex",
29-
flexDirection: "column",
30-
justifyContent: "space-between",
31-
height: "100%",
32-
width: "100%",
33-
fontFamily: primaryFont,
34-
backgroundImage: `url(${siteUrl}/blog-images/social-background.png)`,
35-
padding: "125px 0",
36-
}}
37-
>
38-
<div
39-
style={{
40-
display: "flex",
41-
flexDirection: "column",
42-
width: 1800,
43-
marginLeft: 144,
44-
}}
45-
>
46-
<p
47-
style={{
48-
fontSize: 50,
49-
color: secondaryTextColor,
50-
margin: 0,
51-
}}
52-
>
53-
{displayDate}
54-
</p>
55-
<h1
56-
style={{
57-
fontFamily: titleFont,
58-
fontWeight: 900,
59-
color: primaryTextColor,
60-
fontSize: 144,
61-
margin: 0,
62-
marginTop: 32,
63-
}}
64-
>
65-
{title}
66-
</h1>
67-
</div>
6+
const svg = await createOgImageSVG(request);
687

69-
<Authors authors={authors} />
70-
</div>,
71-
{
72-
width: 2400,
73-
height: 1256,
74-
// Unfortunately satori doesn't support WOFF2 so we have to have a woff version
75-
fonts: [
76-
{
77-
name: titleFont,
78-
data: await getFont(`${siteUrl}/font/inter-roman-latin-var.woff`),
79-
},
80-
{
81-
name: primaryFont,
82-
data: await getFont(`${siteUrl}/font/inter-roman-latin-var.woff`),
83-
},
84-
],
85-
},
86-
);
878
const { data, error } = await new Promise(
889
(
8910
resolve: (value: { data: Buffer | null; error: Error | null }) => void,
@@ -114,68 +35,3 @@ export async function loader({ request }: LoaderFunctionArgs) {
11435
},
11536
});
11637
}
117-
118-
function Authors({
119-
authors,
120-
}: {
121-
authors: ReturnType<typeof getDataFromParams>["authors"];
122-
}) {
123-
// We will have problems if we have more than 2 authors
124-
const picDimensions = authors.length * -60 + 380;
125-
126-
return (
127-
<div style={{ display: "flex", flexDirection: "column", gap: 32 }}>
128-
{authors.map(({ name, title, imgSrc }) => (
129-
<div
130-
style={{
131-
display: "flex",
132-
width: 1600,
133-
marginLeft: 144,
134-
alignItems: "center",
135-
}}
136-
key={name + title}
137-
>
138-
<img
139-
width={picDimensions}
140-
height={picDimensions}
141-
// No alt needed, this is all turning into an image
142-
alt=""
143-
src={imgSrc}
144-
style={{
145-
marginLeft: -40,
146-
borderRadius: 9999,
147-
}}
148-
/>
149-
<h2
150-
style={{
151-
display: "flex",
152-
flexDirection: "column",
153-
marginLeft: 30,
154-
}}
155-
>
156-
<span
157-
style={{
158-
fontFamily: primaryFont,
159-
color: primaryTextColor,
160-
fontSize: 70,
161-
margin: 0,
162-
}}
163-
>
164-
{name}
165-
</span>
166-
<span
167-
style={{
168-
fontFamily: primaryFont,
169-
color: secondaryTextColor,
170-
fontSize: 40,
171-
margin: 0,
172-
}}
173-
>
174-
{title}
175-
</span>
176-
</h2>
177-
</div>
178-
))}
179-
</div>
180-
);
181-
}
File renamed without changes.

app/routes/img.$slug/utils.server.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)