-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnext-sitemap.config.js
42 lines (38 loc) · 1.14 KB
/
next-sitemap.config.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
/** @type {import('next').NextConfig} */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs')
const siteUrl = process.env.NEXT_PUBLIC_DOMAIN_URL
module.exports = {
transform: async (config, path) => {
const noIndexRegex = /(<meta.*(content="noindex").*\/>)/gm
const filepath = `./.next/server/pages/en${path}.html`
if (fs.existsSync(filepath)) {
try {
const data = await fs.promises.readFile(filepath, 'utf8')
if (data.match(noIndexRegex)) return null
} catch (error) {
console.error('err', error)
}
}
return {
loc: path,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
alternateRefs: config.alternateRefs ?? [],
}
},
siteUrl,
exclude: ['/404', '/500', '/docs/api-reference*', '/server-sitemap.xml'],
generateRobotsTxt: true,
robotsTxtOptions: {
policies: [
{
userAgent: '*',
disallow: ['/404'],
},
{ userAgent: '*', allow: '/' },
],
additionalSitemaps: [`${siteUrl}server-sitemap.xml`],
},
}