Skip to content

Commit 647f5ba

Browse files
feat: for kids open graph
1 parent 137a50e commit 647f5ba

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

src/lib/events.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ export function shouldShowProspectus(
273273
);
274274
}
275275

276-
export function getEventDisplayDate(event: CollectionEntry<"events">) {
276+
export function getEventDisplayDate(
277+
event: CollectionEntry<"events"> | CollectionEntry<"forKidsEvent">,
278+
) {
277279
const DRAFT_STATUSES: Array<CollectionEntry<"events">["data"]["status"]> = [
278280
"published-without-date",
279281
"draft",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { apiImageEndpoint } from "@/generated-assets/api";
2+
import type { APIRoute } from "astro";
3+
4+
export const prerender = false;
5+
6+
export const GET: APIRoute = apiImageEndpoint(
7+
import.meta.glob("./_*.tsx", { eager: true }),
8+
);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Frame } from "@/generated-assets/components/Frame";
2+
import {
3+
getAstroImageBase64,
4+
type AssetImageConfig,
5+
} from "@/generated-assets/image";
6+
import { BgImage } from "@/generated-assets/components/BgImage";
7+
import { COLORS } from "@/generated-assets/theme";
8+
9+
import { getEventDisplayDate } from "@/lib/events";
10+
import { getEventData } from "./_utils";
11+
import { LogoForKids } from "@/components/LogoForKids";
12+
13+
export const config: AssetImageConfig = {
14+
width: 1920,
15+
height: 1080,
16+
};
17+
18+
export default async function ({ params }: { params: { id: string } }) {
19+
const event = await getEventData(params.id);
20+
const postCover = await getAstroImageBase64(event.data.image.media);
21+
return (
22+
<Frame {...config} style={{ padding: 128 }}>
23+
<BgImage src={postCover} width={config.width} height={config.height} />
24+
25+
<div
26+
style={{
27+
display: "flex",
28+
flexDirection: "column",
29+
gap: 128,
30+
width: "100%",
31+
justifyContent: "center",
32+
zIndex: 100,
33+
}}
34+
>
35+
<LogoForKids style={{ width: 169 * 3, height: 36 * 3 }} />
36+
37+
<div
38+
style={{
39+
display: "flex",
40+
flexDirection: "column",
41+
gap: 20,
42+
}}
43+
>
44+
<div
45+
style={{
46+
fontSize: 132,
47+
fontWeight: 500,
48+
marginLeft: -6, // Visual alignment
49+
}}
50+
>
51+
{getEventDisplayDate(event)}
52+
</div>
53+
<div
54+
style={{
55+
display: "flex",
56+
fontSize: 80,
57+
fontWeight: 500,
58+
color: COLORS.primary,
59+
marginTop: -16,
60+
marginLeft: -2, // Visual alignment
61+
}}
62+
>
63+
{event.data._computed.city?.data.name},{" "}
64+
{event.data._computed.country?.data.name}
65+
</div>
66+
</div>
67+
</div>
68+
</Frame>
69+
);
70+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { NotFoundAssetError } from "@/generated-assets/api";
2+
import { getEntry, type CollectionEntry } from "astro:content";
3+
4+
export async function forKidsEventWithComputed<
5+
Event extends CollectionEntry<"forKidsEvent">,
6+
>(event: Event) {
7+
const city = await getEntry("cities", event.data.city.id);
8+
9+
const country = city
10+
? await getEntry("countries", city.data.country.id)
11+
: undefined;
12+
13+
const talks = (
14+
event.data.workshops
15+
? await Promise.all(
16+
(event.data.workshops ?? []).map(async (item) => {
17+
if (!item.id) {
18+
return;
19+
}
20+
return await getEntry("forKidsWorkshop", item.id);
21+
}),
22+
)
23+
: []
24+
).filter((i) => !!i);
25+
26+
return {
27+
...event,
28+
data: {
29+
...event.data,
30+
_computed: {
31+
name: `${city?.data.name}, ${country?.data.name}, ${event.data.date.getFullYear()}`,
32+
city,
33+
country,
34+
talks,
35+
},
36+
},
37+
};
38+
}
39+
40+
export const getEventData = async (id: string) => {
41+
const event = await getEntry("forKidsEvent", id);
42+
if (!event) {
43+
throw new NotFoundAssetError();
44+
}
45+
46+
return forKidsEventWithComputed({
47+
...event,
48+
});
49+
};

0 commit comments

Comments
 (0)