-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathposts.ts
More file actions
155 lines (132 loc) Β· 5.68 KB
/
posts.ts
File metadata and controls
155 lines (132 loc) Β· 5.68 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
import { getCollection } from "astro:content";
import type { APIRoute } from "astro";
export const GET: APIRoute = async () => {
const limit = Infinity;
const sponsors = await getCollection("sponsors");
const exclude = ["startup"];
const records: any[] = [];
const charLimits: Record<string, number> = {
instagram: 2200,
x: 280,
linkedin: 3000,
bsky: 300,
fosstodon: 500,
};
const tiers = [
"Keystone",
"Diamond",
"Platinum",
"Platinum X",
"Gold",
"Silver",
"Bronze",
"Patron",
] as const;
const commercialMessages = [
"πβ¨ 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",
"πβ¨ 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",
"πβ¨ 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",
"πβ¨ 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",
"πβ¨ 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",
"πβ¨ A huge thank you to SPONSOR_NAME for sponsoring EuroPython 2025! Your support helps make this event extraordinary. π SPONSOR_HANDLE SPONSOR_URL",
];
const communityMessages = [
"πβ¨ 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",
];
const getRandomMessage = (messages: any) => {
return messages[Math.floor(Math.random() * messages.length)];
};
const isCommercialTier = (tier: any) => {
return tiers.includes(tier);
};
const message_template = {
x: ({ name, handle, url, tier }) => {
const isCommercial = isCommercialTier(tier);
const messages = isCommercial ? commercialMessages : communityMessages;
const template = messages[0];
return template
.replace(/SPONSOR_NAME/g, name)
.replace(/SPONSOR_HANDLE/g, handle)
.replace(/SPONSOR_URL/g, url)
.replace(/SUPPORTER_HANDLE/g, handle)
.replace(/SUPPORTER_URL/g, url);
},
linkedin: ({ name, handle, url, tier }) => {
const isCommercial = isCommercialTier(tier);
const messages = isCommercial ? commercialMessages : communityMessages;
const template = getRandomMessage(messages);
return template
.replace(/SPONSOR_NAME/g, name)
.replace(/SPONSOR_HANDLE/g, handle)
.replace(/SPONSOR_URL/g, url)
.replace(/SUPPORTER_HANDLE/g, handle)
.replace(/SUPPORTER_URL/g, url);
},
bsky: ({ name, handle, url, tier }) => {
const isCommercial = isCommercialTier(tier);
const messages = isCommercial ? commercialMessages : communityMessages;
const template = getRandomMessage(messages);
return template
.replace(/SPONSOR_NAME/g, name)
.replace(/SPONSOR_HANDLE/g, handle)
.replace(/SPONSOR_URL/g, url)
.replace(/SUPPORTER_HANDLE/g, handle)
.replace(/SUPPORTER_URL/g, url);
},
fosstodon: ({ name, handle, url, tier }) => {
const isCommercial = isCommercialTier(tier);
const messages = isCommercial ? commercialMessages : communityMessages;
const template = getRandomMessage(messages);
return template
.replace(/SPONSOR_NAME/g, name)
.replace(/SPONSOR_HANDLE/g, handle)
.replace(/SPONSOR_URL/g, url)
.replace(/SUPPORTER_HANDLE/g, handle)
.replace(/SUPPORTER_URL/g, url);
},
};
const trimToLimit = (text: string, limit: number) =>
text.length <= limit ? text : text.slice(0, limit - 1) + "β¦";
for (const sponsor of sponsors) {
if (records.length >= limit) break;
if (exclude.includes(sponsor.id)) continue;
const { name, url, tier, socials } = sponsor.data;
const sponsorImage = `https://ep2025.europython.eu/media/sponsors/social-${sponsor.id}.png`;
const handles = {
x: socials?.twitter,
linkedin: socials?.linkedin,
bsky: socials?.bluesky,
fosstodon: socials?.mastodon,
};
const generateMessage = (platform: keyof typeof message_template) => {
const templateFn = message_template[platform];
const handle = handles[platform as keyof typeof handles] || "";
const full = templateFn({
name,
handle,
url,
tier,
});
const limit = charLimits[platform];
return trimToLimit(full, limit);
};
const record = {
name,
image: sponsorImage,
handles: handles,
channel: {
x: generateMessage("x"),
linkedin: generateMessage("linkedin"),
bsky: generateMessage("bsky"),
fosstodon: generateMessage("fosstodon"),
},
};
records.push(record);
}
return new Response(JSON.stringify(records, null, 2), {
status: 200,
headers: {
"Content-Type": "application/json",
},
});
};