import { createGetRoutes } from 'virtual:meta-layouts'
import type { RouteMeta } from 'vue-router'
import type { Post } from '~/common/interfaces/Post'

type Meta = {
  frontmatter: {
    title: string
    time: string
    author: string
  }
} & RouteMeta

export default (): Post[] => {
  const router = useRouter()

  const routes = createGetRoutes(router)().filter((route) => {
    return route.path.startsWith('/posts/')
  })

  return routes.map((route) => {
    const meta = route.meta as Meta
    return { path: route.path, ...meta.frontmatter }
  })
}
