Skip to content

Commit 6f07338

Browse files
authored
Add sponsors posts for socials (#1374)
Data used for social media automation.
1 parent 768bed8 commit 6f07338

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
File renamed without changes.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { getCollection, getEntry } from "astro:content";
2+
import type { APIRoute } from "astro";
3+
4+
export const GET: APIRoute = async () => {
5+
const limit = Infinity;
6+
const sponsors = await getCollection("sponsors");
7+
const exclude = ["startup"];
8+
const records: any[] = [];
9+
10+
const charLimits: Record<string, number> = {
11+
instagram: 2200,
12+
x: 280,
13+
linkedin: 3000,
14+
bsky: 300,
15+
fosstodon: 500,
16+
};
17+
18+
const tiers = [
19+
"Keystone",
20+
"Diamond",
21+
"Platinum",
22+
"Platinum X",
23+
"Gold",
24+
"Silver",
25+
"Bronze",
26+
"Patron",
27+
] as const;
28+
29+
const commercialMessages = [
30+
"🎉✨ We are pleased to welcome SPONSOR_NAME as a sponsor for EuroPython 2025! Your support is making a huge difference. We are so grateful for your sponsorship and are thrilled to have you with us. 🙌SPONSOR_HANDLE SPONSOR_URL",
31+
"🚀✨ We are delighted to welcome SPONSOR_NAME as a sponsor for EuroPython 2025! Your support helps make this event extraordinary. We are so grateful for your sponsorship and are thrilled to have you with us. 🙌SPONSOR_HANDLE SPONSOR_URL",
32+
"🎉✨ A big thank you to SPONSOR_NAME for joining us as a sponsor for EuroPython 2025! Your support is making a huge impact. We are so grateful for your sponsorship and are thrilled to have you with us. 🙌SPONSOR_HANDLE SPONSOR_URL",
33+
"🚀✨ Big shoutout and heartfelt thanks to SPONSOR_NAME for sponsoring EuroPython 2025! Your support is crucial in bringing the European Python 🐍 community closer together. We are so grateful for your sponsorship and are thrilled to have you with us. 🙌SPONSOR_HANDLE SPONSOR_URL",
34+
"🎉✨ Thank you to SPONSOR_NAME for sponsoring EuroPython 2025! Your support is making a huge difference. We are so grateful for your sponsorship and are thrilled to have you with us. 🙌SPONSOR_HANDLE SPONSOR_URL",
35+
"🚀✨ A huge thank you to SPONSOR_NAME for sponsoring EuroPython 2025! Your support helps make this event extraordinary. 🙌SPONSOR_HANDLE SPONSOR_URL",
36+
];
37+
38+
const communityMessages = [
39+
"🎉✨ A warm thank you to SPONSOR_NAME for supporting EuroPython 2025! We're proud to be a space where communities come together, and we value the opportunity to collaborate with other communities and open-source projects. 🙌 SUPPORTER_HANDLE SUPPORTER_URL",
40+
];
41+
42+
const getRandomMessage = (messages: any) => {
43+
return messages[Math.floor(Math.random() * messages.length)];
44+
};
45+
46+
const isCommercialTier = (tier: any) => {
47+
return tiers.includes(tier);
48+
};
49+
50+
const message_template = {
51+
linkedin: ({ name, handle, url, tier }) => {
52+
const isCommercial = isCommercialTier(tier);
53+
const messages = isCommercial ? commercialMessages : communityMessages;
54+
const template = getRandomMessage(messages);
55+
56+
return template
57+
.replace(/SPONSOR_NAME/g, name)
58+
.replace(/SPONSOR_HANDLE/g, handle)
59+
.replace(/SPONSOR_URL/g, url)
60+
.replace(/SUPPORTER_HANDLE/g, handle)
61+
.replace(/SUPPORTER_URL/g, url);
62+
},
63+
};
64+
65+
const trimToLimit = (text: string, limit: number) =>
66+
text.length <= limit ? text : text.slice(0, limit - 1) + "…";
67+
68+
for (const sponsor of sponsors) {
69+
if (records.length >= limit) break;
70+
if (exclude.includes(sponsor.id)) continue;
71+
72+
const { name, url, tier, socials } = sponsor.data;
73+
74+
const sponsorImage = `https://ep2025.europython.eu/media/sponsors/social-${sponsor.id}.png`;
75+
76+
// Extract handles for each platform
77+
const handles = {
78+
linkedin: socials?.linkedin,
79+
};
80+
81+
// Generate appropriate messages for each platform
82+
const generateMessage = (platform: keyof typeof message_template) => {
83+
const templateFn = message_template[platform];
84+
const handle = handles[platform as keyof typeof handles] || "";
85+
86+
const full = templateFn({
87+
name,
88+
handle,
89+
url,
90+
tier,
91+
});
92+
93+
const limit = charLimits[platform];
94+
return trimToLimit(full, limit);
95+
};
96+
97+
const record = {
98+
name,
99+
image: sponsorImage,
100+
handles: handles,
101+
channel: {
102+
linkedin: generateMessage("linkedin"),
103+
},
104+
};
105+
106+
records.push(record);
107+
}
108+
109+
return new Response(JSON.stringify(records, null, 2), {
110+
status: 200,
111+
headers: {
112+
"Content-Type": "application/json",
113+
},
114+
});
115+
};

0 commit comments

Comments
 (0)