import axios from 'axios'

export default async ({ addSiteData, addRoute }) => {
  const { data: posts } = await axios.get('https://jsonplaceholder.typicode.com/posts')

  addSiteData({
    title: 'React Static',
  })

  addRoute({
    path: '/blog',
    component: 'src/pages/blog',
    getData: () => ({
      posts,
    }),
    children: posts.map(post => ({
      path: `/post/${post.id}`,
      component: 'src/page/Post',
      getData: () => ({
        post,
      }),
    })),
  })
}
