export default defineEventHandler(async (event) => {
  const name = getRouterParam(event, 'name')

  if (!name || !/^[a-z0-9-]+$/.test(name)) {
    throw createError({ statusCode: 400, statusMessage: 'Invalid page name' })
  }

  const body = await readBody(event)
  await writeYaml(`pages/${name}.yml`, body)
  return { ok: true }
})
