/** * Owner settings for this install. * * Home page redirect: send visitors of the bare home page (/) straight to one * event, for example while an old shared link still points at /. * * import { setHomeRedirect } from 'kody:@you/pie-night/settings' * export default () => setHomeRedirect({ code: 'smith-family-2026' }) // turn on * export default () => setHomeRedirect({ code: null }) // turn off * * The redirect is a temporary 302, so turning it off takes effect right away. * Add ?home to the URL to see the real home page while it is on. */ import { packageStorage } from 'kody:runtime' import { HOME_REDIRECT_KEY, slugify, validSlug } from './pies.ts' import { getEvent } from './store.ts' export async function setHomeRedirect(params: { code: string | null }) { if (params.code == null || params.code === '') { await packageStorage().set(HOME_REDIRECT_KEY, '') return { ok: true, homeRedirect: null, message: 'The home page shows the Pie Night home again.' } } const slug = slugify(params.code) if (!validSlug(slug) || !(await getEvent(slug))) return { ok: false, homeRedirect: null, message: `No event with the code "${params.code}".` } await packageStorage().set(HOME_REDIRECT_KEY, slug) return { ok: true, homeRedirect: slug, message: `/ now sends visitors to /e/${slug} (302).` } } export async function getHomeRedirect() { const raw = await packageStorage().get(HOME_REDIRECT_KEY) return { homeRedirect: typeof raw === 'string' && raw ? raw : null } } export default setHomeRedirect