-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnext-sitemap.config.js
More file actions
35 lines (29 loc) · 928 Bytes
/
next-sitemap.config.js
File metadata and controls
35 lines (29 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/** @type {import('next-sitemap').IConfig} */
const { NEXT_PUBLIC_SITE_URL } = process.env
module.exports = {
siteUrl: NEXT_PUBLIC_SITE_URL,
generateRobotsTxt: true,
generateIndexSitemap: false,
exclude: ['/api', '/api/**', '/article/add'],
additionalPaths: async () => {
let articles = []
// 本地打包不会生成-因为调用接口会失败!
try {
const res = await fetch(`${NEXT_PUBLIC_SITE_URL}/api/articles/all`)
const json = await res.json()
articles = json.code === 0 ? json.data : []
} catch {
articles = []
}
const result = []
articles.map((item) => {
result.push({
loc: `${NEXT_PUBLIC_SITE_URL}/article/${item.id}`, // 页面位置
changefreq: 'daily', // 更新频率
priority: 0.8, // 优先级
lastmod: new Date(item.createdAt).toISOString() // 最后修改时间
})
})
return result
}
}