Skip to content

Commit 85d6198

Browse files
committed
feat(非Vercel生产环境下才写入文件):
1 parent 85c6a20 commit 85d6198

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

lib/utils/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
// 封装异步加载资源的方法
22
import { memo } from 'react'
3+
import BLOG from '@/blog.config'
4+
5+
/**
6+
* 判断是否是Vercel生产环境,主要为了避免写入文件
7+
* @type {boolean}
8+
*/
9+
export const isNotVercelProduction =
10+
process.env.npm_lifecycle_event === 'build' ||
11+
process.env.npm_lifecycle_event === 'export' ||
12+
!BLOG['isProd']
13+
314

415
/**
516
* 判断是否客户端

pages/index.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { getGlobalData, getPostBlocks } from '@/lib/db/getSiteData'
44
import { generateRobotsTxt } from '@/lib/robots.txt'
55
import { generateSitemapXml } from '@/lib/sitemap.xml'
66
import { DynamicLayout } from '@/themes/theme'
7+
import { isNotVercelProduction } from '@/lib/utils'
8+
import { generateRss } from '@/lib/rss'
79

810
/**
911
* 首页布局
@@ -53,12 +55,14 @@ export async function getStaticProps(req) {
5355
}
5456
}
5557

56-
// 生成robotTxt
57-
generateRobotsTxt(props)
58-
// 生成Feed订阅
59-
// generateRss(props)
60-
// 生成
61-
generateSitemapXml(props)
58+
if (isNotVercelProduction) {
59+
// 生成robotTxt
60+
generateRobotsTxt(props)
61+
// 生成Feed订阅
62+
generateRss(props)
63+
// 生成
64+
generateSitemapXml(props)
65+
}
6266

6367
// 生成全文索引 - 仅在 yarn build 时执行 && process.env.npm_lifecycle_event === 'build'
6468

0 commit comments

Comments
 (0)