diff --git a/assets/js/calendar.js b/assets/js/calendar.js
index 49d62d9..fddd005 100644
--- a/assets/js/calendar.js
+++ b/assets/js/calendar.js
@@ -1,18 +1,15 @@
-fetchCalendarData().then(data => {
- var e = document.getElementById("calendar");
- e.innerHTML = e.innerHTML || "";
- var locale = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
- data.forEach(el => {
- e.innerHTML += `
-
-
${el.name}
- in ${el.daysUntil} days
-
-
${el.membersOnly ? "Members Only" : "Open To The Public"}
-
${el.start.toLocaleDateString("en-us",locale)} from ${String(el.start.getHours()).padStart(2,'0')}:${String(el.start.getMinutes()).padStart(2,'0')} until ${String(el.end.getHours()).padStart(2,'0')}:${String(el.end.getMinutes()).padStart(2,'0')}
-
${el.description}
-
`;
- });
+fetchCalendarData().then(events => {
+ const calendarEl = document.getElementById("calendar");
+ const calendar = new FullCalendar.Calendar(calendarEl, {
+ initialView: "dayGridMonth",
+ events,
+ headerToolbar: {
+ left: 'prev,next today',
+ center: 'title',
+ right: 'dayGridMonth,timeGridWeek,timeGridDay'
+ },
+ });
+ calendar.render();
});
async function fetchCalendarData() {
@@ -30,26 +27,25 @@ async function fetchCalendarData() {
.then(data => {
var now = new Date(Date.now());
var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());
- data.forEach(element => {
- var start = new Date(element.start * 1000);
- var end = new Date(element.end * 1000);
- var durationDay = new Date(start.getFullYear(),start.getMonth(), start.getDate());
- var diffTime = Math.abs(durationDay - today);
- var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
- element.start = start;
- element.end = end;
- element.daysUntil = diffDays;
- });
- data = data.sort((a,b) => {
+
+ return data.map(element => {
+ const title = element.name;
+ const start = new Date(element.start * 1000);
+ const end = new Date(element.end * 1000);
+ const durationDay = new Date(start.getFullYear(),start.getMonth(), start.getDate());
+ const diffTime = Math.abs(durationDay - today);
+ const daysUntil = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
+
+ return {title, start, end, daysUntil};
+ }).sort((a,b) => {
if (a.daysUntil > b.daysUntil) return 1;
else if (b.daysUntil > a.daysUntil) return -1;
else if (a.name > b.name) return -1;
else if (b.name > a.name) return 1;
return 0;
});
- return data;
})
.catch(error => {
console.error('Error:', error);
});
- }
\ No newline at end of file
+ }
diff --git a/pages/calendar.md b/pages/calendar.md
index bc5f09f..c98ae76 100644
--- a/pages/calendar.md
+++ b/pages/calendar.md
@@ -11,6 +11,6 @@ hero:
enabled: false
---
-
-
-
\ No newline at end of file
+
+
+