Something went wrong. Try again.
https://clembs.com
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829import { z } from 'astro/zod';
const ThemeSchema = z.object({ 'color-scheme': z.literal('light').or(z.literal('dark')).or(z.literal('auto')), 'global-base-hue': z.coerce.number().min(0).max(360),});
export async function POST(context: Astro) { const formData = await context.request.formData(); const formDataObject = Object.fromEntries(formData.entries());
const newTheme = ThemeSchema.parse(formDataObject);
context.cookies.set('base-hue', newTheme['global-base-hue'].toString(), { path: '/', }); if (newTheme['color-scheme'] !== 'auto') { context.cookies.set('color-scheme', newTheme['color-scheme'], { path: '/', }); } else { context.cookies.delete('color-scheme', { path: '/' }); }
// redirect to requesting page const referer = context.request.headers.get('referer')!; return context.redirect(referer, 303);}