feat: build official Goldebek municipal website
Deploy / validate-dispatch (push) Successful in 1s
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 6s
Deploy / app-quality (push) Successful in 1m16s
Deploy / secret-scan (push) Successful in 4s
Deploy / security-deps (push) Successful in 18s
Deploy / context (push) Successful in 1s
Deploy / app-image (push) Successful in 1m28s
Deploy / deploy-master (push) Skipped
Deploy / deploy-dev (push) Successful in 13s
Deploy / validate-dispatch (push) Successful in 1s
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 6s
Deploy / app-quality (push) Successful in 1m16s
Deploy / secret-scan (push) Successful in 4s
Deploy / security-deps (push) Successful in 18s
Deploy / context (push) Successful in 1s
Deploy / app-image (push) Successful in 1m28s
Deploy / deploy-master (push) Skipped
Deploy / deploy-dev (push) Successful in 13s
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const isoDate = z.string().refine((value) => {
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
||||
const date = new Date(`${value}T00:00:00Z`);
|
||||
return !Number.isNaN(date.valueOf()) && date.toISOString().startsWith(value);
|
||||
}, "Ungültiges ISO-Datum");
|
||||
|
||||
const time = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/);
|
||||
|
||||
export const eventSchema = z.object({
|
||||
id: z.string().min(1), slug: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/), title: z.string().min(1),
|
||||
summary: z.string().optional(), startDate: isoDate, startTime: time.optional(), endDate: isoDate.optional(), endTime: time.optional(),
|
||||
timezone: z.literal("Europe/Berlin"), location: z.string().optional(), organizer: z.string().optional(),
|
||||
sourceUrl: z.string().url().optional(), sourceName: z.string().optional(), lastVerified: isoDate,
|
||||
status: z.enum(["verified", "dynamic", "needs-verification", "archived"]), privacyApproved: z.boolean().optional(),
|
||||
}).superRefine((event, context) => {
|
||||
if ((event.endDate ?? event.startDate) < event.startDate) context.addIssue({ code: "custom", message: "Das Enddatum liegt vor dem Startdatum." });
|
||||
if (event.location && /\b\d+[a-z]?\b/i.test(event.location) && event.privacyApproved !== true) context.addIssue({ code: "custom", path: ["privacyApproved"], message: "Eine Adresse benötigt privacyApproved=true." });
|
||||
if (["verified", "dynamic"].includes(event.status) && (!event.sourceName || !event.sourceUrl)) context.addIssue({ code: "custom", path: ["sourceUrl"], message: "Veröffentlichte Termine benötigen eine Quelle." });
|
||||
});
|
||||
|
||||
export const newsSchema = z.object({
|
||||
id: z.string().min(1), slug: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/), title: z.string().min(1), teaser: z.string().min(1), body: z.string().min(1),
|
||||
publishedAt: isoDate, updatedAt: isoDate.optional(),
|
||||
image: z.object({ src: z.string(), alt: z.string().min(1), copyright: z.string().optional() }).optional(),
|
||||
sourceUrl: z.string().url().optional(), sourceName: z.string().optional(), lastVerified: isoDate,
|
||||
status: z.enum(["published", "draft", "archived"]),
|
||||
});
|
||||
|
||||
export const sourceSchema = z.object({
|
||||
id: z.string().min(1), name: z.string().min(1), url: z.string().url(), type: z.string().min(1), lastVerified: isoDate,
|
||||
});
|
||||
|
||||
export type Event = z.infer<typeof eventSchema>;
|
||||
export type NewsItem = z.infer<typeof newsSchema>;
|
||||
export type Source = z.infer<typeof sourceSchema>;
|
||||
|
||||
export function assertUnique<T>(items: T[], key: (item: T) => string, label: string): void {
|
||||
const seen = new Set<string>();
|
||||
for (const item of items) {
|
||||
const value = key(item);
|
||||
if (seen.has(value)) throw new Error(`Doppelter ${label}: ${value}`);
|
||||
seen.add(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user