-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.tsx
More file actions
161 lines (151 loc) · 4.35 KB
/
Copy pathroute.tsx
File metadata and controls
161 lines (151 loc) · 4.35 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { ImageResponse } from "next/og";
import { getTranslations } from "next-intl/server";
import { getBeanBySlug, getBrewingMethod } from "@/lib/data";
import { formatBrewTime } from "@/lib/utils";
export const runtime = "nodejs";
const WIDTH = 1200;
const HEIGHT = 630;
const BG_FROM = "#1A0F09";
const BG_TO = "#3B2314";
const CREAM = "#FAF6F1";
const TAN = "#D4C4A8";
const CHERRY = "#C1440E";
export async function GET(req: Request) {
const { searchParams } = new URL(req.url);
const locale = searchParams.get("locale") === "zh-TW" ? "zh-TW" : "en";
const beanSlug = searchParams.get("bean");
const methodId = searchParams.get("method");
const bean = beanSlug ? getBeanBySlug(beanSlug.trim(), locale) : undefined;
const rec = bean?.brewingRecommendations.find((r) => r.methodId === methodId);
const method = methodId ? getBrewingMethod(methodId, locale) : undefined;
if (!bean || !rec) {
return new ImageResponse(
(
<div
style={{
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
backgroundImage: `linear-gradient(135deg, ${BG_FROM}, ${BG_TO})`,
color: CREAM,
}}
>
<div style={{ display: "flex", fontSize: 72, fontWeight: 700 }}>
☕ BeanMap
</div>
</div>
),
{ width: WIDTH, height: HEIGHT },
);
}
// Localized labels, with English fallbacks if translations are unavailable
// in this (non-locale-routed) request context.
let labels = {
badge: "Recipe",
grind: "Grind",
temp: "Temp",
ratio: "Ratio",
time: "Time",
};
try {
const t = await getTranslations({ locale, namespace: "recipeCard" });
labels = {
badge: t("badge"),
grind: t("grind"),
temp: t("temp"),
ratio: t("ratio"),
time: t("time"),
};
} catch {
// keep English fallbacks
}
const params: Array<{ label: string; value: string }> = [
{ label: labels.grind, value: `~${rec.grindMicrons}μm` },
{ label: labels.temp, value: `${rec.waterTempC}°C` },
{ label: labels.ratio, value: rec.ratio },
{ label: labels.time, value: formatBrewTime(rec.brewSeconds) },
];
return new ImageResponse(
(
<div
style={{
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
padding: 64,
backgroundImage: `linear-gradient(135deg, ${BG_FROM}, ${BG_TO})`,
color: CREAM,
}}
>
<div
style={{
display: "flex",
alignItems: "center",
fontSize: 32,
color: TAN,
letterSpacing: 1,
}}
>
☕ BeanMap · {labels.badge}
</div>
<div style={{ display: "flex", flexDirection: "column", marginTop: 24 }}>
<div style={{ display: "flex", fontSize: 64, fontWeight: 700 }}>
{method?.name ?? methodId}
</div>
<div style={{ display: "flex", fontSize: 34, color: TAN, marginTop: 8 }}>
{bean.name} · {bean.country}
</div>
</div>
<div
style={{
display: "flex",
marginTop: "auto",
gap: 24,
}}
>
{params.map((p) => (
<div
key={p.label}
style={{
display: "flex",
flexDirection: "column",
flex: 1,
padding: "20px 24px",
borderRadius: 16,
border: `1px solid ${TAN}`,
}}
>
<div
style={{
display: "flex",
fontSize: 24,
color: TAN,
textTransform: "uppercase",
letterSpacing: 1,
}}
>
{p.label}
</div>
<div
style={{
display: "flex",
fontSize: 40,
fontWeight: 700,
color: CHERRY,
marginTop: 6,
}}
>
{p.value}
</div>
</div>
))}
</div>
</div>
),
{ width: WIDTH, height: HEIGHT },
);
}