import axios from 'axios'

export default async ({ addSiteData, addRouteData }) => {
  // Register some site data. Use this
  addSiteData({
    title: 'React Static',
  })

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

  addRouteData('blog', {
    posts,
  })

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