import axios from 'axios'

export default async ({
  addSiteData, addData, addRoute, addRedirect,
}) => {
  addSiteData({
    title: 'React Static',
  })

  const { data: posts } = await axios.get('https://jsonplaceholder.typicode.com/posts')
  addData({
    posts,
  })

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