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' })
  }

  try {
    return await readYaml(`pages/${name}.yml`)
  }
  catch {
    throw createError({ statusCode: 404, statusMessage: `Page "${name}" not found` })
  }
})
