This commit is contained in:
parent
e5b078da25
commit
fffc6a912b
3 changed files with 72 additions and 55 deletions
|
@ -6,41 +6,41 @@
|
|||
const uriRegex =
|
||||
/(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/\-_\.\:]*(\?\S+)?)?)?)/gi;
|
||||
|
||||
const timeFormat = new Intl.DateTimeFormat("de-DE", {
|
||||
dateStyle: "full",
|
||||
timeStyle: "short",
|
||||
hourCycle: "h23",
|
||||
});
|
||||
|
||||
export default function hackcal(e, p = 1) {
|
||||
if (!document.getElementById("dbkcalendar")) return;
|
||||
|
||||
const calendar = document.getElementById("calendar").content.cloneNode(true);
|
||||
const calendarDate = document.getElementById("calendar-date");
|
||||
const calendarEntry = document.getElementById("calendar-entry");
|
||||
|
||||
const calendarParent = document.getElementById("dbkcalendar");
|
||||
const body = calendar.querySelector("tbody");
|
||||
calendarParent.innerHTML = "";
|
||||
|
||||
const calUri = `https://hackcal.ctbk.de/?period=${p}`;
|
||||
fetch(calUri)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
const items = [];
|
||||
Object.keys(data).forEach(function (date) {
|
||||
const day = new Date(date);
|
||||
|
||||
const dateItem = calendarDate.content.cloneNode(true);
|
||||
const timeElement = dateItem.querySelector("time");
|
||||
timeElement.innerText = day.toLocaleDateString(true, {
|
||||
weekday: "short",
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
});
|
||||
timeElement.dateTime = date;
|
||||
body.appendChild(dateItem);
|
||||
|
||||
Object.keys(data[date]).forEach(function (uid) {
|
||||
const event = data[date][uid];
|
||||
|
||||
const startTime = event.dtstart;
|
||||
const day = new Date(startTime);
|
||||
console.log(day);
|
||||
|
||||
const dateItem = calendarDate.content.cloneNode(true);
|
||||
const timeElement = dateItem.querySelector("time");
|
||||
timeElement.innerText = timeFormat.format(day);
|
||||
timeElement.dateTime = date;
|
||||
calendarParent.appendChild(dateItem);
|
||||
|
||||
const entryItem = calendarEntry.content.cloneNode(true);
|
||||
entryItem.querySelector(".calendar-entry").dataset.uid = uid;
|
||||
entryItem.querySelector(".time").innerText = event.datestr;
|
||||
|
||||
// use description as link on summary if it's a valid URL
|
||||
const summaryItem = entryItem.querySelector(".summary");
|
||||
|
@ -79,11 +79,8 @@ export default function hackcal(e, p = 1) {
|
|||
categoriesParent.appendChild(categoryItem);
|
||||
}
|
||||
|
||||
body.appendChild(entryItem);
|
||||
calendarParent.appendChild(entryItem);
|
||||
});
|
||||
});
|
||||
|
||||
calendarParent.innerHTML = "";
|
||||
calendarParent.appendChild(calendar);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue