import fs from "node:fs"; import path from "node:path"; import { z } from "zod"; const root=path.resolve(import.meta.dirname,".."); const read=(file)=>JSON.parse(fs.readFileSync(path.join(root,file),"utf8")); const iso=z.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value)=>new Date(`${value}T00:00:00Z`).toISOString().startsWith(value),"invalid date"); const eventSchema=z.object({id:z.string().min(1),slug:z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),title:z.string().min(1),startDate:iso,startTime:z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/).optional(),endDate:iso.optional(),endTime:z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/).optional(),timezone:z.literal("Europe/Berlin"),location:z.string().optional(),sourceUrl:z.string().url().optional(),sourceName:z.string().optional(),lastVerified:iso,status:z.enum(["verified","dynamic","needs-verification","archived"]),privacyApproved:z.boolean().optional()}); const sourceSchema=z.object({id:z.string().min(1),name:z.string().min(1),url:z.string().url(),type:z.string().min(1),lastVerified:iso}); const newsSchema=z.object({id:z.string().min(1),slug:z.string(),title:z.string(),teaser:z.string(),body:z.string(),publishedAt:iso,updatedAt:iso.optional(),lastVerified:iso,status:z.enum(["published","draft","archived"]),sourceUrl:z.string().url().optional(),sourceName:z.string().optional()}); const pagesSchema=z.array(z.object({slug:z.string().regex(/^[a-z0-9-]+(?:\/[a-z0-9-]+)*$/),title:z.string(),intro:z.string(),sections:z.array(z.object({title:z.string(),text:z.array(z.string()).optional(),items:z.array(z.string()).optional(),links:z.array(z.object({label:z.string(),href:z.string(),external:z.boolean().optional()})).optional()})),sourceId:z.string().optional(),lastVerified:iso.optional(),special:z.string().optional()})); const events=eventSchema.array().parse(read("content/events/events.json")); const news=newsSchema.array().parse([read("content/news/spielplatz-am-langbarg.json")]); const sources=sourceSchema.array().parse(read("data/sources.json")); const pages=pagesSchema.parse(read("content/pages/pages.json")); const services=read("data/services.json"); const council=read("data/council.json"); const projects=read("data/projects.json"); const demographics=read("data/demographics.json"); const administration=read("data/administration.json"); const community=read("data/community.json"); const sourceIds=new Set(sources.map((item)=>item.id)); const unique=(items,key,label)=>{const seen=new Set();for(const item of items){const value=item[key];if(seen.has(value))throw new Error(`Doppelter ${label}: ${value}`);seen.add(value);}}; unique(events,"slug","Termin-Slug");unique(news,"slug","News-Slug");unique(pages,"slug","Seiten-Slug");unique(sources,"id","Quellen-ID"); for(const event of events){if((event.endDate??event.startDate)`/${page.slug}`),...events.map((event)=>`/termine/${event.slug}`),...news.map((item)=>`/aktuelles/${item.slug}`)]); for(const page of pages){for(const section of page.sections){for(const link of section.links??[]){if(link.href.startsWith("/")&&!routeSet.has(link.href.split("#")[0]))throw new Error(`Interner Link ohne Ziel auf ${page.slug}: ${link.href}`);}}} console.log(`Content validiert: ${pages.length} Seiten, ${news.length} Meldung, ${events.length} Termine, ${sources.length} Quellen.`);