fix ical validation errors

This commit is contained in:
Fabrice Lamant
2024-07-23 21:55:42 +02:00
parent f426bea344
commit 6c38dbb1f5
196 changed files with 4487 additions and 11523 deletions

View File

@ -19,7 +19,27 @@ const generateICS = (title, key, events) => {
lines.push(
...Object.entries(event)
.filter(([key]) => !key.startsWith("_"))
.map(([key, value]) => `${key}:${value}`),
.map(([key, value]) => {
let result = `${key}:${value}`;
if (result.length > 75) {
if (key === "DESCRIPTION") {
const lines = [];
while (result.length > 75) {
let index = 75;
while (result[index] !== " " && index > 0) {
index--;
}
lines.push(result.slice(0, index));
result = " " + result.slice(index);
}
lines.push(result);
return lines.join("\r\n").trim();
}
return `${key}:${value}`.slice(0, 75);
}
return `${key}:${value}`;
}),
);
lines.push("END:VEVENT");
});

View File

@ -135,9 +135,9 @@ const extractSportCalendar = async (sportKey) => {
// more than two, we put them in the description
competitors.forEach((competitor) => {
if (competitor.name !== getNOCName(competitor.noc)) {
event.DESCRIPTION += `\r\n${getNOCFlag(competitor.noc)} ${competitor.name}`;
event.DESCRIPTION += `\\n${getNOCFlag(competitor.noc)} ${competitor.name}`;
} else {
event.DESCRIPTION += `\r\n${getNOCFlag(competitor.noc)} ${competitor.noc}`;
event.DESCRIPTION += `\\n${getNOCFlag(competitor.noc)} ${competitor.noc}`;
}
});
}