mirror of
https://git.p-schwarz.de/ctbk/ctbk.de.git
synced 2025-05-18 21:35:34 +00:00
26 lines
1.5 KiB
JavaScript
26 lines
1.5 KiB
JavaScript
/*
|
|
Include calendar | Chaostreff Backnang | @paddy
|
|
*/
|
|
document.addEventListener("DOMContentLoaded", hackcal);
|
|
|
|
function hackcal(p=1) {
|
|
var cal_uri = "/hackcal/?period="+p;
|
|
var uri_regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/\-_\.\:]*(\?\S+)?)?)?)/ig
|
|
|
|
fetch(cal_uri).then(res => res.json()).then(data => {
|
|
var items = [];
|
|
Object.keys(data).forEach(function (date) {
|
|
var day = new Date(date);
|
|
items.push("<div data-date='" + date + "'><span>" + day.toLocaleDateString(true, {weekday:'short', day:'numeric', month:'long', year: 'numeric'}) + "</span></div>");
|
|
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("<div data-uid='" + uid + "'><span>" + event.datestr + "</span><span><b>" + event.summary + "</b> | " + location + "<br/>" + description + categories + "</span></div>");
|
|
});
|
|
});
|
|
document.querySelector('#dbkcalendar').innerHTML = items.join( "" );
|
|
});
|
|
}
|
|
|