import axios from 'axios'

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

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

  // data
  // registerTemplates // use pages directory as default for templates
  // addRoutes
}

export default {
  getSiteData: () => ({
    title: 'React Static',
  }),
  getRoutes: async () => {
    const { data: posts } = await axios.get('https://jsonplaceholder.typicode.com/posts')
    return [
      {
        path: '/',
        component: 'src/containers/Home',
      },
      {
        path: '/about',
        component: 'src/containers/About',
      },
      {
        path: '/blog',
        component: 'src/containers/Blog',
        getData: () => ({
          posts,
        }),
        children: posts.map(post => ({
          path: `/post/${post.id}`,
          component: 'src/containers/Post',
          getData: () => ({
            post,
          }),
        })),
      },
      {
        is404: true,
        component: 'src/containers/404',
      },
    ]
  },
}
