Initial commit
Deploy / validate-dispatch (push) Successful in 43s
Deploy / scheduled-rebuild-dev (push) Skipped
Deploy / scheduled-rebuild-master (push) Skipped
Deploy / rollback-dev (push) Skipped
Deploy / rollback-master (push) Skipped
Deploy / changes (push) Successful in 13s
Deploy / secret-scan (push) Successful in 9s
Deploy / app-quality (push) Successful in 11m21s
Deploy / security-deps (push) Successful in 14s
Deploy / context (push) Failing after 1s
Deploy / app-image (push) Skipped
Deploy / deploy-dev (push) Skipped
Deploy / deploy-master (push) Skipped
Deploy / validate-dispatch (push) Successful in 43s
Deploy / scheduled-rebuild-dev (push) Skipped
Deploy / scheduled-rebuild-master (push) Skipped
Deploy / rollback-dev (push) Skipped
Deploy / rollback-master (push) Skipped
Deploy / changes (push) Successful in 13s
Deploy / secret-scan (push) Successful in 9s
Deploy / app-quality (push) Successful in 11m21s
Deploy / security-deps (push) Successful in 14s
Deploy / context (push) Failing after 1s
Deploy / app-image (push) Skipped
Deploy / deploy-dev (push) Skipped
Deploy / deploy-master (push) Skipped
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @fileoverview Hilfsfunktionen zum Formatieren von Kalender-Events
|
||||
*
|
||||
* Diese Module bietet Funktionen zur Formatierung von Event-Start- und Endzeiten
|
||||
* in deutsches Format, Handling von ganztägigen Events und Berechnung der
|
||||
* effektiven Endzeit eines Events.
|
||||
*
|
||||
* @module utils/eventFormat
|
||||
*/
|
||||
|
||||
import type { CalendarEvent } from "../types";
|
||||
|
||||
// Dauer eines Tages in Millisekunden
|
||||
const DAY_IN_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* Formatiert ein Datum für den Vergleich
|
||||
*
|
||||
* Wandelt ein Date-Objekt in ein formatiertes String um (JJJJ-MM-TT) unter
|
||||
* Berücksichtigung der angegebenen Zeitzone.
|
||||
*
|
||||
* @param date - Das zu formatierende Datum
|
||||
* @param timeZone - Die Zeitzone (z.B. "Europe/Berlin")
|
||||
* @returns Formattierte Datums-ID für Vergleichszwecke
|
||||
*/
|
||||
function formatDateKey(date: Date, timeZone: string) {
|
||||
return new Intl.DateTimeFormat("en-CA", {
|
||||
timeZone,
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet die effektive Endzeit eines Events
|
||||
*
|
||||
* Für ganztägige Events wird die Endzeit auf 23:59:59.999 gesetzt, um
|
||||
* sicherzustellen, dass das Event am gesamten Tag sichtbar bleibt.
|
||||
* Für mehrday-Events wird die Endzeit korrekt berechnet.
|
||||
*
|
||||
* @param event - Das Event, dessen Endzeit berechnet werden soll
|
||||
* @returns Die effektive Endzeit des Events
|
||||
*/
|
||||
export function getEffectiveEventEnd(event: CalendarEvent): Date {
|
||||
const end = new Date(event.end);
|
||||
if (event.allDay) {
|
||||
end.setHours(23, 59, 59, 999);
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert den Zeitraum eines Events für die Anzeige
|
||||
*
|
||||
* Generiert einen benutzerfreundlichen String, der das Start- und Enddatum
|
||||
* (und Uhrzeit) des Events enthält. Die Daten werden in deutschem Format
|
||||
* angezeigt, wobei die Zeitzone des Events berücksichtigt wird.
|
||||
*
|
||||
* Ganztägige Events und mehrday-Events werden korrekt verküpft oder
|
||||
* zusammengefasst.
|
||||
*
|
||||
* @param event - Das zu formatierende Event
|
||||
* @returns Formattierter Zeitraum (z.B. "15. Januar 2025 · 14:00 – 18:00")
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* formatEventDateRange(event) // returns "15. Januar 2025 · 14:00 – 18:00"
|
||||
* ```
|
||||
*/
|
||||
export function formatEventDateRange(event: CalendarEvent) {
|
||||
const startDate = new Date(event.start);
|
||||
const endDate = new Date(event.end);
|
||||
const dateFormatter = new Intl.DateTimeFormat("de-DE", {
|
||||
dateStyle: "long",
|
||||
timeZone: event.timeZone,
|
||||
});
|
||||
const timeFormatter = new Intl.DateTimeFormat("de-DE", {
|
||||
timeStyle: "short",
|
||||
timeZone: event.timeZone,
|
||||
});
|
||||
|
||||
if (event.allDay) {
|
||||
const inclusiveEnd =
|
||||
endDate.getTime() > startDate.getTime()
|
||||
? new Date(endDate.getTime() - DAY_IN_MS)
|
||||
: startDate;
|
||||
const startKey = formatDateKey(startDate, event.timeZone);
|
||||
const endKey = formatDateKey(inclusiveEnd, event.timeZone);
|
||||
if (startKey === endKey) {
|
||||
return dateFormatter.format(startDate);
|
||||
}
|
||||
return `${dateFormatter.format(startDate)} – ${dateFormatter.format(
|
||||
inclusiveEnd
|
||||
)}`;
|
||||
}
|
||||
|
||||
const startKey = formatDateKey(startDate, event.timeZone);
|
||||
const endKey = formatDateKey(endDate, event.timeZone);
|
||||
if (startKey === endKey) {
|
||||
return `${dateFormatter.format(startDate)} · ${timeFormatter.format(
|
||||
startDate
|
||||
)} – ${timeFormatter.format(endDate)}`;
|
||||
}
|
||||
return `${dateFormatter.format(startDate)} ${timeFormatter.format(
|
||||
startDate
|
||||
)} – ${dateFormatter.format(endDate)} ${timeFormatter.format(endDate)}`;
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
import type { CalendarEvent } from "../types";
|
||||
import { formatEventDateRange, getEffectiveEventEnd } from "./eventFormat";
|
||||
|
||||
const HERO_SPECIAL_LIMIT = 5;
|
||||
|
||||
export interface CalendarEventGroup {
|
||||
label: string;
|
||||
events: CalendarEvent[];
|
||||
}
|
||||
|
||||
export function filterUpcomingEvents(events: CalendarEvent[], now = new Date()): CalendarEvent[] {
|
||||
const limit = new Date(now);
|
||||
limit.setUTCHours(23, 59, 59, 999);
|
||||
limit.setUTCMonth(limit.getUTCMonth() + 12);
|
||||
|
||||
return events
|
||||
.filter((event) => {
|
||||
const start = new Date(event.start);
|
||||
return getEffectiveEventEnd(event) >= now && start <= limit;
|
||||
})
|
||||
.sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime());
|
||||
}
|
||||
|
||||
export function getSpecialEvents(events: CalendarEvent[], now = new Date()): CalendarEvent[] {
|
||||
return events
|
||||
.filter((event) => event.special && getEffectiveEventEnd(event) >= now)
|
||||
.slice(0, HERO_SPECIAL_LIMIT);
|
||||
}
|
||||
|
||||
export function getCalendarGroups(
|
||||
events: CalendarEvent[],
|
||||
now = new Date(),
|
||||
): CalendarEventGroup[] {
|
||||
const upcomingEvents = filterUpcomingEvents(events, now);
|
||||
const groups = new Map<string, CalendarEventGroup>();
|
||||
|
||||
for (const event of upcomingEvents) {
|
||||
const start = new Date(event.start);
|
||||
const parts = new Intl.DateTimeFormat("en-CA", {
|
||||
timeZone: event.timeZone,
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
}).formatToParts(start);
|
||||
const year = parts.find((part) => part.type === "year")?.value;
|
||||
const month = parts.find((part) => part.type === "month")?.value;
|
||||
const key = `${year}-${month}`;
|
||||
|
||||
if (!groups.has(key)) {
|
||||
groups.set(key, {
|
||||
label: new Intl.DateTimeFormat("de-DE", {
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
timeZone: event.timeZone,
|
||||
}).format(start),
|
||||
events: [],
|
||||
});
|
||||
}
|
||||
|
||||
groups.get(key)?.events.push(event);
|
||||
}
|
||||
|
||||
return Array.from(groups.values());
|
||||
}
|
||||
|
||||
function createMessageElement(
|
||||
documentRef: Document,
|
||||
className: string,
|
||||
message: string,
|
||||
): HTMLParagraphElement {
|
||||
const element = documentRef.createElement("p");
|
||||
element.className = className;
|
||||
element.textContent = message;
|
||||
return element;
|
||||
}
|
||||
|
||||
export function createSpecialEventsFragment(
|
||||
documentRef: Document,
|
||||
events: CalendarEvent[],
|
||||
): DocumentFragment {
|
||||
const fragment = documentRef.createDocumentFragment();
|
||||
const specialEvents = getSpecialEvents(events);
|
||||
|
||||
if (!specialEvents.length) {
|
||||
fragment.append(
|
||||
createMessageElement(
|
||||
documentRef,
|
||||
"muted",
|
||||
"Aktuell sind keine besonderen Termine geplant.",
|
||||
),
|
||||
);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
const wrapper = documentRef.createElement("div");
|
||||
wrapper.className = "hero-special-events";
|
||||
|
||||
const list = documentRef.createElement("ul");
|
||||
const dateFormatter = new Intl.DateTimeFormat("de-DE", { dateStyle: "long" });
|
||||
|
||||
for (const event of specialEvents) {
|
||||
const item = documentRef.createElement("li");
|
||||
const title = documentRef.createElement("span");
|
||||
title.className = "group-name";
|
||||
title.textContent = event.title;
|
||||
|
||||
const date = documentRef.createElement("span");
|
||||
date.textContent = dateFormatter.format(new Date(event.start));
|
||||
|
||||
item.append(title, date);
|
||||
list.append(item);
|
||||
}
|
||||
|
||||
const note = documentRef.createElement("p");
|
||||
note.className = "calendar-note";
|
||||
note.append("Alle Termine mit weiteren Details findest Du im ");
|
||||
|
||||
const link = documentRef.createElement("a");
|
||||
link.href = "/kalender";
|
||||
link.textContent = "Kalender";
|
||||
|
||||
note.append(link, ".");
|
||||
|
||||
wrapper.append(list, note);
|
||||
fragment.append(wrapper);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
export function createCalendarFragment(
|
||||
documentRef: Document,
|
||||
events: CalendarEvent[],
|
||||
): DocumentFragment {
|
||||
const fragment = documentRef.createDocumentFragment();
|
||||
const groups = getCalendarGroups(events);
|
||||
|
||||
if (!groups.length) {
|
||||
fragment.append(
|
||||
createMessageElement(
|
||||
documentRef,
|
||||
"muted",
|
||||
"In den nächsten 12 Monaten sind noch keine Termine geplant.",
|
||||
),
|
||||
);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
const wrapper = documentRef.createElement("div");
|
||||
wrapper.className = "calendar-table";
|
||||
|
||||
for (const group of groups) {
|
||||
const month = documentRef.createElement("section");
|
||||
month.className = "calendar-table-month";
|
||||
month.setAttribute("aria-label", group.label);
|
||||
|
||||
const heading = documentRef.createElement("h2");
|
||||
heading.className = "calendar-month-heading";
|
||||
heading.textContent = group.label;
|
||||
|
||||
const table = documentRef.createElement("div");
|
||||
table.className = "calendar-table-grid";
|
||||
table.setAttribute("role", "table");
|
||||
|
||||
const headerRow = documentRef.createElement("div");
|
||||
headerRow.className = "calendar-table-row calendar-table-row-head";
|
||||
headerRow.setAttribute("role", "row");
|
||||
|
||||
const titleHeader = documentRef.createElement("span");
|
||||
titleHeader.className = "calendar-table-title";
|
||||
titleHeader.setAttribute("role", "columnheader");
|
||||
titleHeader.textContent = "Termin";
|
||||
|
||||
const dateHeader = documentRef.createElement("span");
|
||||
dateHeader.className = "calendar-table-date";
|
||||
dateHeader.setAttribute("role", "columnheader");
|
||||
dateHeader.textContent = "Datum & Uhrzeit";
|
||||
|
||||
headerRow.append(titleHeader, dateHeader);
|
||||
table.append(headerRow);
|
||||
|
||||
for (const event of group.events) {
|
||||
const row = documentRef.createElement("div");
|
||||
row.className = "calendar-table-row";
|
||||
row.setAttribute("role", "row");
|
||||
|
||||
const titleCell = documentRef.createElement("span");
|
||||
titleCell.className = "calendar-table-title";
|
||||
titleCell.setAttribute("role", "cell");
|
||||
|
||||
const titleWrapper = documentRef.createElement("span");
|
||||
titleWrapper.className = "calendar-event-title";
|
||||
|
||||
if (event.special) {
|
||||
const highlight = documentRef.createElement("span");
|
||||
highlight.className = "calendar-highlight";
|
||||
highlight.textContent = "★";
|
||||
titleWrapper.append(highlight, " ");
|
||||
}
|
||||
|
||||
titleWrapper.append(event.title);
|
||||
titleCell.append(titleWrapper);
|
||||
|
||||
if (event.location) {
|
||||
const location = documentRef.createElement("span");
|
||||
location.className = "calendar-event-location";
|
||||
location.textContent = `, ${event.location}`;
|
||||
titleCell.append(location);
|
||||
}
|
||||
|
||||
const dateCell = documentRef.createElement("span");
|
||||
dateCell.className = "calendar-table-date";
|
||||
dateCell.setAttribute("role", "cell");
|
||||
dateCell.textContent = formatEventDateRange(event);
|
||||
|
||||
row.append(titleCell, dateCell);
|
||||
table.append(row);
|
||||
}
|
||||
|
||||
month.append(heading, table);
|
||||
wrapper.append(month);
|
||||
}
|
||||
|
||||
fragment.append(wrapper);
|
||||
return fragment;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export function serializeJsonLd(value: unknown): string {
|
||||
return JSON.stringify(value)
|
||||
.replaceAll("<", "\\u003C")
|
||||
.replaceAll(">", "\\u003E")
|
||||
.replaceAll("&", "\\u0026")
|
||||
.replaceAll("\u2028", "\\u2028")
|
||||
.replaceAll("\u2029", "\\u2029");
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @fileoverview Hilfsfunktionen für die Behandlung von Beiträgen (Posts)
|
||||
*
|
||||
* Dieses Modul bietet Funktionen zum Sortieren von Beiträgen und Extrahieren von
|
||||
* Textinhalten aus Markdown.
|
||||
*
|
||||
* @module utils/postUtils
|
||||
*/
|
||||
|
||||
import type { PostMetadata } from "../types";
|
||||
|
||||
/**
|
||||
* Sortiert eine Liste von Beiträgen nach Erstellungsdatum (neueste zuerst)
|
||||
*
|
||||
* @param {PostMetadata[]} posts - Array von Beitrags-Metadaten
|
||||
* @returns {PostMetadata[]} Sortiertes Array (neueste zuerst)
|
||||
*/
|
||||
export function sortPostsByCreatedDate(posts: PostMetadata[]): PostMetadata[] {
|
||||
return [...posts].sort((a, b) => {
|
||||
const dateB = b.createdAt.getTime();
|
||||
const dateA = a.createdAt.getTime();
|
||||
return dateB - dateA;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Extrahiert reinen Text aus Markdown-Inhalten
|
||||
*
|
||||
* Entfernt HTML-Tags, Markdown-Syntax (Headings, Bold, etc.), Links und
|
||||
* normalisiert Whitespace für eine saubere Textdarstellung.
|
||||
*
|
||||
* @param {string} content - Markdown-Textinhalt
|
||||
* @returns {string} Reiner Textinhalt ohne Markdown-Syntax
|
||||
*/
|
||||
export function extractPlainText(content: string): string {
|
||||
return content
|
||||
.replace(/<[^>]+>/g, " ")
|
||||
.replace(/[#>*_`~\\-]+/g, " ")
|
||||
.replace(/\[(.*?)\]\(.*?\)/g, "$1")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen kurzen Auszug (Excerpt) aus Text
|
||||
*
|
||||
* Schneidet den Text nach der maxLength ab und fügt "..." hinzu,
|
||||
* wenn der Text zu lang ist.
|
||||
*
|
||||
* @param {string} plainText - Der zu kürzende Text
|
||||
* @param {number} maxLength - Maximale Länge des Auszugs
|
||||
* @returns {string} Der gekürzte Auszug
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* createExcerpt("Das ist ein sehr langer Text", 10) // returns "Das ist e..."
|
||||
* ```
|
||||
*/
|
||||
export function createExcerpt(plainText: string, maxLength: number): string {
|
||||
if (plainText.length <= maxLength) {
|
||||
return plainText;
|
||||
}
|
||||
return `${plainText.slice(0, Math.max(0, maxLength - 3))}...`;
|
||||
}
|
||||
Reference in New Issue
Block a user