most of the initial structure and content
This commit is contained in:
parent
a486b7bbb7
commit
d7b50372a8
11 changed files with 517 additions and 83 deletions
|
@ -1,65 +1,85 @@
|
|||
/*
|
||||
Include calendar | Chaostreff Backnang | @paddy
|
||||
Modernization by @kleinesfilmroellchen
|
||||
*/
|
||||
|
||||
export default function hackcal(e, p = 1) {
|
||||
// var cal_uri = "https://chaostreff-backnang.de/hackcal/?period=" + p;
|
||||
var cal_uri = "/hackcal";
|
||||
var uri_regex =
|
||||
/(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/\-_\.\:]*(\?\S+)?)?)?)/gi;
|
||||
if (!document.getElementById("dbkcalendar")) return;
|
||||
|
||||
fetch(cal_uri)
|
||||
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");
|
||||
|
||||
// const cal_uri = "https://chaostreff-backnang.de/hackcal/?period=" + p;
|
||||
const calUri = "/hackcal";
|
||||
fetch(calUri)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
var items = [];
|
||||
const items = [];
|
||||
Object.keys(data).forEach(function (date) {
|
||||
var day = new Date(date);
|
||||
items.push(
|
||||
"<tr class='' data-date='" +
|
||||
date +
|
||||
"'><span>" +
|
||||
day.toLocaleDateString(true, {
|
||||
weekday: "short",
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
}) +
|
||||
"</span></tr>"
|
||||
);
|
||||
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) {
|
||||
var event = data[date][uid];
|
||||
var location = event.location
|
||||
? event.location
|
||||
.replace(/\n/g, "<br>")
|
||||
.replace(uri_regex, "<a href='$1' target='_blank'>$1</a>")
|
||||
: "";
|
||||
var description = event.description
|
||||
? event.description
|
||||
.replace(/\n/g, "<br>")
|
||||
.replace(uri_regex, (url) => {
|
||||
event.summary = `<a href='${url}' target='_blank'>${event.summary}</a>`;
|
||||
return "";
|
||||
})
|
||||
: "";
|
||||
var categories = event.categories
|
||||
? "<i>" + event.categories.replace(",", "</i> <i>") + "</i>"
|
||||
: "";
|
||||
items.push(
|
||||
"<tr data-uid='" +
|
||||
uid +
|
||||
"'><span>" +
|
||||
event.datestr +
|
||||
"</span><span><b>" +
|
||||
event.summary +
|
||||
"</b> | " +
|
||||
location +
|
||||
"<br/>" +
|
||||
description +
|
||||
categories +
|
||||
"</span></tr>"
|
||||
);
|
||||
const event = data[date][uid];
|
||||
|
||||
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");
|
||||
try {
|
||||
const descriptionUri = new URL(event.description);
|
||||
const descriptionLink = document.createElement("a");
|
||||
descriptionLink.href = descriptionUri;
|
||||
descriptionLink.target = "_blank";
|
||||
descriptionLink.innerText = event.summary;
|
||||
summaryItem.appendChild(descriptionLink);
|
||||
} catch (e) {
|
||||
summaryItem.innerText = event.summary;
|
||||
entryItem.querySelector(".description").innerText =
|
||||
event.description;
|
||||
}
|
||||
|
||||
// self-link location if it's a valid URL
|
||||
const locationItem = entryItem.querySelector(".location");
|
||||
try {
|
||||
const locationUri = new URL(event.location);
|
||||
const locationLink = document.createElement("a");
|
||||
locationLink.href = locationUri;
|
||||
locationLink.target = "_blank";
|
||||
locationLink.innerText = event.location;
|
||||
locationItem.appendChild(locationLink);
|
||||
} catch (e) {
|
||||
locationItem.innerText = event.location;
|
||||
}
|
||||
|
||||
const categoriesParent = entryItem.querySelector(".categories");
|
||||
for (const category of event.categories.split(",")) {
|
||||
const categoryItem = document.createElement("em");
|
||||
categoryItem.innerText = category;
|
||||
categoriesParent.appendChild(categoryItem);
|
||||
}
|
||||
|
||||
body.appendChild(entryItem);
|
||||
});
|
||||
});
|
||||
document.querySelector("#dbkcalendar").innerHTML = items.join("");
|
||||
|
||||
calendarParent.innerHTML = "";
|
||||
calendarParent.appendChild(calendar);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue