Skip to content

Commit

Permalink
display reocurring tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
geritwagner committed Jan 15, 2025
1 parent 5abc106 commit 6efd8c4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
71 changes: 48 additions & 23 deletions .github/workflows/generate_ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,59 @@ function parseDateTime(dateTimeString) {
}

async function loadEvents() {
const yamlText = fs.readFileSync('docs/calendar/events.yaml', 'utf8');
const events = yaml.load(yamlText);
try {
const response = await fetch('calendar/events.yaml');
if (!response.ok) {
throw new Error("Network response was not ok: " + response.statusText);
}
const yamlText = await response.text();
const events = jsyaml.load(yamlText);

if (!Array.isArray(events)) {
throw new Error('Parsed YAML is not an array');
}
if (!Array.isArray(events)) {
throw new Error("Parsed YAML is not an array");
}

return events
.map(event => {
const start = parseDateTime(event.start);
const end = parseDateTime(event.end);
const expandedEvents = [];
for (const event of events) {
const startDate = new Date(event.start);
const endDate = new Date(event.end);

if (!start || !end) {
console.warn(`Skipping event with invalid dates: ${JSON.stringify(event)}`);
return null; // Skip invalid events
}
if (event.recurrence) {
const [ruleKey, ruleValue] = event.recurrence.split(':');
if (ruleKey === 'FREQ') {
const rrule = new RRule({
...RRule.parseString(ruleValue),
dtstart: startDate,
});

return {
start,
end,
title: event.title,
description: event.description || '',
location: event.location || '',
recurrence: event.recurrence || null, // Include recurrence if provided
};
})
.filter(event => event !== null); // Filter out invalid events
rrule.all().forEach(date => {
const end = new Date(date.getTime() + (endDate - startDate));
expandedEvents.push({
start: date.toISOString(),
end: end.toISOString(),
title: event.title,
color: event.color,
location: event.location,
description: event.description,
});
});
}
} else {
// Non-recurring event
expandedEvents.push({
start: event.start,
end: event.end,
title: event.title,
color: event.color,
});
}
}

return expandedEvents;
} catch (error) {
console.error("Error fetching or parsing YAML:", error);
return [];
}
}

function generateICal(events) {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_calendar_ics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
node-version: '16'

- name: Install dependencies
run: npm install js-yaml ics luxon
run: npm install js-yaml ics luxon rrule

- name: Generate iCal File
run: node .github/workflows/generate_ical.js
Expand Down
1 change: 1 addition & 0 deletions docs/02.calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nav_order: 3
<script src="https://cdn.jsdelivr.net/npm/@event-calendar/[email protected]/event-calendar.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"></script>
<script src="calendar/ics.js"></script>
<script src="https://cdn.jsdelivr.net/npm/rrule/dist/es5/rrule.min.js"></script>

# 02 Calendar

Expand Down

0 comments on commit 6efd8c4

Please sign in to comment.