我正在使用nextjs和本示例https://github.com/zeit/next.js/tree/master/examples/with-static-export
在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({},{
'/': { page: '/' },})
},}
它获取3个帖子并生成文件-[id] .html-非常好!
但是现在我只需要获取新帖子并为此新帖子构建页面,但是很抱歉下一步导出,请删除所有文件并仅创建一个帖子。
我该怎么做才能保留旧帖子并在下一次导出时添加新帖子?
示例:
- 第一个下一次导出,要求从api请求3个帖子
- 在“ out”文件夹中生成3个帖子
- 更改api网址并为1个新帖子运行下一个导出
- 摘要,我的“出”目录中有3个旧帖子页面和1个新帖子页面
该怎么做?