-
Notifications
You must be signed in to change notification settings - Fork 1
/
next-sitemap.js
58 lines (54 loc) · 1.44 KB
/
next-sitemap.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const { readFileSync } = require('fs')
const { join } = require('path')
module.exports = {
siteUrl: 'https://cyprusjs.org',
generateRobotsTxt: true,
changefreq: 'daily',
priority: 0.7,
sitemapSize: 5000,
exclude: ['[fallback]', '404', '[postname].js'],
transform: async (config, path) => {
const relPath = join(__dirname, config.sourceDir, 'server', 'pages', path)
const relFile = relPath + '.json'
let date = new Date().toISOString()
try {
const file = readFileSync(relFile, 'utf8')
const parsed = JSON.parse(file)
if (
(parsed &&
parsed.pageProps &&
parsed.pageProps.meta &&
parsed.pageProps.meta.updatedAt) ||
parsed.pageProps.meta.date
) {
if (parsed.pageProps.meta.updatedAt) {
date = new Date(parsed.pageProps.meta.updatedAt).toISOString()
} else {
date = new Date(parsed.pageProps.meta.date).toISOString()
}
}
if (parsed && parsed.pageProps.meta.draft === true) {
return
}
} catch (error) {
console.info('sitemap: file not found, moving on.')
}
if (!path.endsWith('/')) {
path = path + '/'
}
return {
loc: path,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.autoLastmod ? date : undefined
}
},
robotsTxtOptions: {
policies: [
{
userAgent: '*',
allow: '/'
}
]
}
}