-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
311 lines (272 loc) · 11.6 KB
/
index.html
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!DOCTYPE html>
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BarcelonaJS Event Generator</title>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--padding: 64px;
--w: 1500px;
--h: 500px;
}
.Canvas {
border-radius: 2px;
margin: auto;
transition: all .3s;
background-color: #000000;
width: calc(var(--w) - var(--padding) * 2);
height: calc(var(--h));
position: relative;
padding: var(--padding)
}
.Motto {
font-size: 130px;
letter-spacing: 1px;
font-weight: 700;
margin: 0;
}
.Date {
font-size: 36px;
margin: 0 0 0 9px;
}
.Logo {
position: absolute;
bottom: var(--padding);
right: var(--padding);
}
.Info {
position: absolute;
bottom: var(--padding);
}
.Info h3 {
font-size: 42px;
}
.Info h4 {
font-size: 36px;
}
.Info h3,
.Info h4 {
margin: 0;
}
/* UI */
main {
display: block;
margin: auto;
font-family: 'Noto Sans JP', sans-serif;
color: white;
}
header {
transition: all .3s;
margin: auto;
max-width: var(--w);
display: flex;
justify-content: space-between;
align-items: center;
padding: 24px 0;
}
</style>
</head>
<body>
<header>
<nav>
<select id="issue-selector" onchange="fetchMainIssue(this.value)">
</select>
<button id="btn-download-meetup" onclick="handleMeetupClick()">Download Meetup</button>
<button id="btn-download-twitter" onclick="handleTwitterClick()">Download Twitter</button>
</nav>
</header>
<hr />
<div id="issue-content">
</div>
<hr />
<main>
<div class="Canvas">
<h1 class="Motto">BarcelonaJS</h1>
<h2 class="Date"></h2>
<div class="Info">
<h3> Offered by:</h3>
<h4 class="Company"></h4>
</div>
<img class="Logo" src="./logo.png" />
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
function extractSponsorDescription(text) {
const sponsorDescriptionRegex = /### Sponsor Description\r\n\r\n([\s\S]*?)\r\n\r\n### Code of Conduct/;
const match = text.match(sponsorDescriptionRegex);
if (match) {
return match[1]
.trim()
.split('\n')
.map(line => `<p>${line.trim()}</p>`)
.join('');
} else {
return '';
}
}
function parseEventDetails(issueBody) {
return {
eventDate: extractDetail(issueBody, /- When: (.+)/),
eventTime: "19:00",
sponsorName: extractDetail(issueBody, /- Sponsor: (.+) \/ /),
sponsorWebsiteUrl: extractDetail(issueBody, /- Sponsor: .+ \/ (.+)/),
sponsorDescription: extractSponsorDescription(issueBody)
};
}
function parseTalkDetails(talkIssue) {
const talkDetails = {
title: talkIssue.title,
description: extractMultilineDetail(talkIssue.body, /### Talk Description\n\n([\s\S]+?)\n\n###/),
speakerName: extractDetail(talkIssue.body, /### Speaker Name\n\n(.+?)\n\n/),
speakerPosition: extractDetail(talkIssue.body, /### Speaker Position\n\n(.+?)\n\n/),
speakerLinkedIn: extractDetail(talkIssue.body, /### Speaker LinkedIn\n\n(.+?)\n\n/),
speakerTwitter: extractDetail(talkIssue.body, /### Speaker Twitter\n\n(.+?)\n\n/),
speakerCompany: extractDetail(talkIssue.body, /### Speaker Company Name\n\n(.+?)\n\n/),
speakerCompanyWebsite: extractDetail(talkIssue.body, /### Speaker Company Website\n\n(.+?)\n\n/),
speakerCompanyLinkedIn: extractDetail(talkIssue.body, /### Speaker Company LinkedIn\n\n(.+?)\n\n/),
speakerCompanyTwitter: extractDetail(talkIssue.body, /### Speaker Company Twitter\n\n(.+?)\n\n/)
};
return talkDetails;
}
function extractMultilineDetail(text, regex) {
const match = text.replace(/\r/g, '').match(regex);
if (match) {
return match[1]
.trim()
.split('\n')
.map(line => line.trim() ? `<p>${line.trim()}</p>` : '')
.join('');
} else {
return '';
}
}
function extractDetail(text, regex) {
const match = text.replace(/\r/g, '').match(regex);
if (match) {
return match[1].trim();
} else {
return '';
}
}
function constructEventDescription(eventDetails, talksDetails) {
let description = `<p>Hello everyone! Join us for the next meetup. As always, we will have two talks followed by a networking session.</p>`;
// Assuming talksDetails[0] and talksDetails[1] are the first and second talks
description += `<hr>`;
description += formatTalk(talksDetails[0]);
description += `<hr>`;
description += formatTalk(talksDetails[1]);
description += `<hr>`;
description += `
<p><strong>IMPORTANT!</strong></p>
<p>Security:</p>
<ul>
<li>Access control: The security team requires an attendees list. Make sure you register for the event with your full name. Registration will close 24h before the event.</li>
<li>You'll be asked to provide your name and ID (DNI, NIE, etc.) to access the building.</li>
</ul>
<hr>
<p>After the talks, we'll have drinks and networking!</p>
<p>Are you interested in giving a talk or have a question? You are welcome to comment or shoot a meetup message to the organizers.</p>
<p>And don't forget to follow us on Twitter for the latest news <a href="https://twitter.com/BcnJS">@BcnJS</a></strong></p>
<hr>
<p><strong>Sponsors:</strong></p>
<p><strong><a href="${eventDetails.sponsorWebsiteUrl}">${eventDetails.sponsorName}</a></strong></p>
<p>${eventDetails.sponsorDescription}</p>`;
return description;
}
function formatTalk(talk) {
const speakerLink = talk.speakerTwitter || talk.speakerLinkedIn;
const companyLink = talk.speakerCompanyWebsite || talk.speakerCompanyLinkedIn || talk.speakerCompanyTwitter;
return `<p><strong>${talk.title}</strong></p>
<p>by <a href="${speakerLink}">${talk.speakerName}</a></p>
<p>${talk.speakerPosition} at <a href="${companyLink}">${talk.speakerCompany}</a></p>
<p>${talk.description}</p>`;
}
function fetchIssueList() {
const issuesApiUrl = 'https://api.github.com/repos/barcelonajs/events/issues';
fetch(issuesApiUrl)
.then(response => response.json())
.then(issues => {
const selector = document.getElementById('issue-selector');
issues.forEach(issue => {
const option = document.createElement('option');
option.value = issue.number;
option.textContent = issue.title;
selector.appendChild(option);
});
fetchMainIssue(issues[0].number)
})
.catch(error => console.error('Error:', error));
}
function fetchMainIssue(issueNumber) {
const mainIssueUrl = `https://api.github.com/repos/BarcelonaJS/events/issues/${issueNumber}`;
fetch(mainIssueUrl)
.then(response => response.json())
.then(mainIssueData => {
const eventDetails = parseEventDetails(mainIssueData.body);
const talkIssueDetails = extractTalkIssueNumbers(mainIssueData.body);
const talkDetailsPromises = talkIssueDetails.map(detail =>
fetchTalkDetails(detail.repo, detail.number)
);
document.querySelector('.Company').innerText = "@" + eventDetails?.sponsorName;
document.querySelector('.Date').innerText = eventDetails?.eventDate + " " + eventDetails?.eventTime;
Promise.all(talkDetailsPromises)
.then(talksDetails => {
const combinedContent = constructEventDescription(eventDetails, talksDetails);
document.getElementById('issue-content').innerHTML = combinedContent;
});
})
.catch(error => console.error('Error:', error));
}
function extractTalkIssueNumbers(issueBody) {
const issueNumberRegex = /https:\/\/github\.com\/BarcelonaJS\/([^\/]+)\/issues\/(\d+)/gi;
let match;
const issueDetails = [];
while ((match = issueNumberRegex.exec(issueBody)) !== null) {
issueDetails.push({
repo: match[1],
number: match[2]
});
}
return issueDetails;
}
function fetchTalkDetails(repo, issueNumber) {
const talkIssueUrl = `https://api.github.com/repos/BarcelonaJS/${repo}/issues/${issueNumber}`;
return fetch(talkIssueUrl)
.then(response => response.json())
.then(talkIssueData => {
return parseTalkDetails(talkIssueData);
});
}
function handleTwitterClick() {
document.documentElement.style.setProperty('--w', 1500 + "px");
document.documentElement.style.setProperty('--h', 500 + "px");
const canvas = document.querySelector('.Canvas');
html2canvas(canvas).then(function (canvas) {
const link = document.createElement('a');
link.download = 'logo.png';
link.href = canvas.toDataURL();
link.click();
});
}
function handleMeetupClick() {
document.documentElement.style.setProperty('--w', 1500 + "px");
document.documentElement.style.setProperty('--h', 720 + "px");
const canvas = document.querySelector('.Canvas');
html2canvas(canvas).then(function (canvas) {
const link = document.createElement('a');
link.download = 'logo.png';
link.href = canvas.toDataURL();
link.click();
});
}
fetchIssueList();
</script>
</body>
</html>