next.config.js 713 字节
Newer Older
1
const fetch = require('isomorphic-unfetch')
2 3 4 5

module.exports = {
  async exportPathMap () {
    // we fetch our list of posts, this allow us to dynamically generate the exported pages
6 7 8
    const response = await fetch(
      'https://jsonplaceholder.typicode.com/posts?_page=1'
    )
9 10 11 12 13 14
    const postList = await response.json()

    // tranform the list of posts into a map of pages with the pathname `/post/:id`
    const pages = postList.reduce(
      (pages, post) =>
        Object.assign({}, pages, {
15
          [`/post/${post.id}`]: { page: '/post/[id]' }
16
        }),
T
Tim Neutkens 已提交
17
      {}
18 19 20 21 22 23 24 25
    )

    // combine the map of post pages with the home
    return Object.assign({}, pages, {
      '/': { page: '/' }
    })
  }
}