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

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

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