werkstaetten-app/src/routes/termine.ics/+server.ts
Friederich Loheide bef8574e07 Werkstatt-App: öffentliche PWA und Redaktions-Backend
Werbefreie, barrierearme Info-App für Werkstätten (WfbM) auf Basis von
SvelteKit, Tailwind, SQLite/Drizzle:

- App: Startseite mit Kacheln, Meldungen, Seitenbaum, Termine inkl.
  Schließzeiten und iCal-Abo, Ansprechpartner, Suche, Kontaktformular,
  Merkliste, Vorlesen, Leichte Sprache, Schriftgrößen, Hell/Dunkel, PWA
- Redaktion: Dashboard, Meldungen, Seiten, Termine, Kacheln,
  Ansprechpartner, Mediathek mit Bildoptimierung, Postfach, Benutzer
  mit Rollen, Einstellungen (Name, Logo, Farbe, Rechtstexte)
- Demo-Seed, CLI zum Anlegen von Benutzern, Dockerfile und Compose

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-29 20:55:13 +00:00

45 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { upcomingEvents } from '$lib/server/content';
import { getSettings } from '$lib/server/settings';
import { addDays, today } from '$lib/dates';
/** Kalender-Abo (iCal) – z. B. für Handy-Kalender oder Outlook. */
export const GET = ({ url }) => {
const s = getSettings();
const esc = (v: string) => v.replace(/\\/g, '\\\\').replace(/;/g, '\;').replace(/,/g, '\\,').replace(/\r?\n/g, '\\n');
const d = (iso: string) => iso.replaceAll('-', '');
const t = (time: string) => time.replace(':', '') + '00';
const stamp = new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d+/, '');
const lines = [
'BEGIN:VCALENDAR',
'VERSION:2.0',
`PRODID:-//${esc(s.appName)}//Termine//DE`,
'CALSCALE:GREGORIAN',
`X-WR-CALNAME:${esc(s.appName)}`,
'X-WR-TIMEZONE:Europe/Berlin'
];
for (const e of upcomingEvents({ from: addDays(today(), -60) })) {
const end = e.endDate || e.startDate;
lines.push('BEGIN:VEVENT', `UID:event-${e.id}@${url.host}`, `DTSTAMP:${stamp}`);
if (e.startTime && end === e.startDate) {
lines.push(`DTSTART;TZID=Europe/Berlin:${d(e.startDate)}T${t(e.startTime)}`);
lines.push(`DTEND;TZID=Europe/Berlin:${d(end)}T${t(e.endTime || e.startTime)}`);
} else {
lines.push(`DTSTART;VALUE=DATE:${d(e.startDate)}`, `DTEND;VALUE=DATE:${d(addDays(end, 1))}`);
}
lines.push(`SUMMARY:${esc(e.kind === 'closure' ? `Geschlossen: ${e.title}` : e.title)}`);
if (e.location) lines.push(`LOCATION:${esc(e.location)}`);
if (e.description) lines.push(`DESCRIPTION:${esc(e.description)}`);
lines.push('END:VEVENT');
}
lines.push('END:VCALENDAR');
return new Response(lines.join('\r\n'), {
headers: {
'Content-Type': 'text/calendar; charset=utf-8',
'Content-Disposition': 'inline; filename="termine.ics"',
'Cache-Control': 'public, max-age=900'
}
});
};