Repository navigation
Expand file tree
/
Copy patheleventy.config.js
More file actions
472 lines (444 loc) · 11.2 KB
/
Copy patheleventy.config.js
File metadata and controls
472 lines (444 loc) · 11.2 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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
require('dotenv').config();
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];
const dataFromCMS = async (query, maxRetries = 5) => {
const baseDelayMs = 1000; // Start with 1 second (as recommended by Hygraph)
const maxDelayMs = 5000; // Cap at 5 seconds
for (let attempt = 0; attempt <= maxRetries; attempt++) {
try {
const response = await fetch(process.env.CMS_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query }),
});
const json = await response.json();
// Check for concurrent operations limit error (HTTP 429 or GraphQL error)
const isConcurrencyError =
response.status === 429 ||
(json.errors &&
json.errors.some(
(e) =>
e.message &&
e.message
.toLowerCase()
.includes(
'concurrent operations limit exceeded'
)
));
if (isConcurrencyError && attempt < maxRetries) {
// Exponential backoff: 1s, 2s, 4s, 5s, 5s...
const delay = Math.min(
baseDelayMs * Math.pow(2, attempt),
maxDelayMs
);
console.log(
`⚠️ Concurrent operations limit hit. Retrying in ${delay}ms (attempt ${
attempt + 1
}/${maxRetries + 1})...`
);
await new Promise((resolve) => setTimeout(resolve, delay));
continue;
}
if (!response.ok || json.errors || !json.data) {
console.error(
'CMS response error:',
JSON.stringify(
{
status: response.status,
statusText: response.statusText,
errors: json.errors,
dataPresent: !!json.data,
},
null,
2
)
);
if (attempt < maxRetries && !isConcurrencyError) {
// Retry for other errors too, but with backoff
const delay = Math.min(
baseDelayMs * Math.pow(2, attempt),
maxDelayMs
);
console.log(
`⚠️ Retrying in ${delay}ms (attempt ${attempt + 1}/${
maxRetries + 1
})...`
);
await new Promise((resolve) => setTimeout(resolve, delay));
continue;
}
}
return json.data;
} catch (error) {
if (attempt < maxRetries) {
const delay = Math.min(
baseDelayMs * Math.pow(2, attempt),
maxDelayMs
);
console.log(
`⚠️ Network error. Retrying in ${delay}ms (attempt ${
attempt + 1
}/${maxRetries + 1})...`
);
await new Promise((resolve) => setTimeout(resolve, delay));
continue;
}
throw error;
}
}
throw new Error('Failed to fetch CMS data after all retries');
};
const fetchPeopleFromCMS = async () => {
const pageSize = 100;
const people = [];
while (true) {
const skip = people.length;
console.log(` → Fetching people ${skip + 1}-${skip + pageSize}...`);
const data = await dataFromCMS(`query {
people(orderBy: role_ASC, first:${pageSize}, skip:${skip}) {
name
slug
photo {
url
}
title
school
role
homepage
biography {
html
text
}
}
}`);
const page = data?.people || [];
people.push(...page);
if (page.length < pageSize) {
return people;
}
}
};
module.exports = function (config) {
config.addPassthroughCopy('images');
config.addPassthroughCopy('styles');
config.addPassthroughCopy('src/site.webmanifest');
config.addPassthroughCopy('src/favicon.ico');
config.addFilter('day', (dateString) => new Date(dateString).getUTCDate());
config.addFilter(
'month',
(dateString) => months[new Date(dateString).getUTCMonth()]
);
config.addFilter('year', (dateString) =>
new Date(dateString).getUTCFullYear()
);
config.addFilter('monthYear', (dateString) => {
const date = new Date(dateString);
return `${months[date.getUTCMonth()]} ${date.getUTCFullYear()}`;
});
config.addFilter('date', (dateString) => {
const date = new Date(dateString);
return `${
months[date.getUTCMonth()]
} ${date.getUTCDate()}, ${date.getUTCFullYear()}`;
});
config.addFilter('squeezeTag', (content) =>
/^<([a-zA-Z]+)>.*<\/\1>$/.test(content)
? content.replace(/^<[a-zA-Z]+>|<\/[a-zA-Z]+>$/g, '')
: content
);
config.addFilter('squeezeParagraphTag', (content) =>
/^<[pP]>.*<\/[pP]>$/.test(content)
? content.replace(/^<[pP]>|<\/[pP]>$/g, '')
: content
);
config.addFilter('multilineHtml', (content) =>
content ? content.replace('\n', '<br>') : ''
);
config.addGlobalData('cms', async () => {
console.log('Fetching CMS data in batches...');
try {
// Batch 1: Core site info (basic + website)
console.log(' → Fetching basic + website...');
const batch1 = await dataFromCMS(`query {
basic(where: {id: "clnctyp51hrrk0bmz4xfaxc5r"}) {
name
longName
shortIntro {
text
html
}
logo {
url
}
email
address
whatWeDo {
text
html
}
whoWeAre {
text
html
}
publications {
text
html
}
joinUs {
html
text
}
events {
text
html
}
}
website(where: {id: "clncxqdc8iccb0bk92yv12dm8"}) {
navigationBar {
name
links {
name
slug
}
slug
}
bigMailIcon {
url
}
bigMapIcon {
url
}
coursesIcon {
url
}
downIcon {
url
}
emailIcon {
url
}
gitHubIcon {
url
}
homeHeaderBackground {
url
}
opportunitiesImage {
url
}
resourcesIcon {
url
}
softwareIcon {
url
}
title
xIcon {
url
}
youTubeIcon {
url
}
}
}`);
// Batch 2: Social media
console.log(' → Fetching social media...');
const batch2 = await dataFromCMS(`query {
socialMedias(orderBy: priority_ASC) {
name
priority
url
icon {
url
}
}
}`);
// Batch 3: Events
console.log(' → Fetching events...');
const batch3 = await dataFromCMS(`query {
events(orderBy: date_DESC, first: 1000) {
date
title
topic
details {
html
text
}
hosts {
name
title
school
homepage
}
slug
}
}`);
// Batch 4: Papers
console.log(' → Fetching papers...');
const batch4 = await dataFromCMS(`query {
papers(orderBy: date_DESC, first:1000) {
date
title
slug
abstract {
html
text
}
authors {
name
homepage
}
url
links {
name
url
}
softwares {
name
url
slug
}
publication {
name
url
}
}
}`);
// Batch 5: People
const people = await fetchPeopleFromCMS();
// Batch 6: Policy
console.log(' → Fetching policy...');
const batch6 = await dataFromCMS(`query {
policy(where: {id: "clnfo8kqodbgx0blpxqd6uo7s"}) {
details {
html
text
}
effectiveDate
}
}`);
// Batch 7: Softwares
console.log(' → Fetching softwares...');
const batch7 = await dataFromCMS(`query {
softwares {
name
slug
url
description {
html
text
}
papers {
title
slug
}
}
}`);
// Batch 8: Links
console.log(' → Fetching links...');
const batch8 = await dataFromCMS(`query {
links {
name
url
}
}`);
// Batch 9: Projects
console.log(' → Fetching projects...');
const batch9 = await dataFromCMS(`query {
projects(first:100) {
date
description {
html
text
}
image {
url
}
links {
url
name
}
slug
softwares {
name
url
}
collaborators {
name
homepage
}
title
url
}
}`);
// Batch 10: Learning resources
console.log(' → Fetching learning resources...');
const batch10 = await dataFromCMS(`query {
learningResourceCategories {
name
slug
learningResources {
title
slug
lastUpdate
level
description {
html
text
}
url
authors {
name
homepage
}
}
}
}`);
// Combine all batches
const cmsData = {
basic: batch1?.basic || {},
website: batch1?.website || {},
socialMedias: batch2?.socialMedias || [],
events: batch3?.events || [],
papers: batch4?.papers || [],
people,
policy: batch6?.policy || {},
softwares: batch7?.softwares || [],
links: batch8?.links || [],
projects: batch9?.projects || [],
learningResourceCategories:
batch10?.learningResourceCategories || [],
};
console.log('✅ CMS data fetched successfully (all batches)');
return cmsData;
} catch (error) {
console.error('Error fetching CMS data:', error.message);
return {
basic: {},
website: {},
socialMedias: [],
events: [],
papers: [],
people: [],
policy: {},
softwares: [],
links: [],
projects: [],
learningResourceCategories: [],
};
}
});
return { dir: { input: 'src' } };
};