import axios from 'axios'

export default async ({ addSiteData, addRouteData }) => {
  // Register some site data. Use <SiteData> to consume in your app
  addSiteData({
    title: 'React Static',
  })

  // We can fetch any data we want, however we want!
  const { data: posts } = await axios.get('https://jsonplaceholder.typicode.com/posts')

  // Let's supply all of the blog posts to the /blog route
  addRouteData({
    path: 'blog',
    data: {
      posts,
    },
  })

  // Let's also add each post to it's appropriate route
  posts.forEach(post => addRouteData({
    path: `blog/post/${post.id}`,
    data: {
      post,
    },
  })
}
