Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Next.js Nextjs export clear";“出去”;文件夹_Next.js_Next - Fatal编程技术网

Next.js Nextjs export clear";“出去”;文件夹

Next.js Nextjs export clear";“出去”;文件夹,next.js,next,Next.js,Next,我正在使用nextjs和这个示例 在next.config.js中,我有代码: module.exports = { async exportPathMap(defaultPathMap, { dev, dir, outDir, distDir, buildId, incremental }) { // we fetch our list of posts, this allow us to dynamically generate the exported pages co

我正在使用nextjs和这个示例

在next.config.js中,我有代码:

module.exports = {
  async exportPathMap(defaultPathMap, { dev, dir, outDir, distDir, buildId, incremental }) {
    // we fetch our list of posts, this allow us to dynamically generate the exported pages
    const response = await fetch(
      'https://jsonplaceholder.typicode.com/posts?_limit=3'
    )
    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, {
          [`/post/${post.id}`]: { page: '/post/[id]' },
        }),
      {}
    )

    // combine the map of post pages with the home
    return Object.assign({}, pages, {
      '/': { page: '/' },
    })
  },
}
它可以获取3篇文章并生成文件-[id].html-太棒了

但现在我需要获取新帖子并只为这篇新帖子构建页面,但commadnext export删除所有文件并只创建一篇帖子

我需要做什么才能保留旧的帖子并在下次导出时添加新的帖子

例如:

  • 第一次下一次导出,请求api发布3篇文章
  • 在文件夹“out”中生成3篇文章
  • 更改api url并为1篇新文章运行下一次导出
  • 我有3个旧的帖子页面和1个新的在我的“out”目录中

如何做到这一点?

下一步无法做到这一点,但您可以设置它来做到这一点。首先,您需要一个系统(数据库),其中已经构建了页面。其次,您需要一些与数据库(api)通信的方法来询问应该构建哪些页面(例如,发送页面列表,api响应告诉您哪些页面尚未构建)。然后,告诉您的
exportPathMap
要构建哪些页面。最后,将构建的页面移出
out
并移动到新的final/public目录中

默认情况下,Next将生成/导出
页面
目录中的任何内容,以及在
导出路径映射
中设置的任何内容,并将所有这些内容放在
输出
目录中。您可以通过传递自定义的
exportPathMap
来覆盖它生成的内容,如何处理进入
out
目录的内容取决于您,因此您可以将这些文件移动到不同的实际公共目录,并将其与旧文件合并