-
Notifications
You must be signed in to change notification settings - Fork 2
/
next-sitemap.config.js
39 lines (38 loc) · 1.22 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
/** @type {import('next-sitemap').IConfig} */
const siteUrl = process.env.NEXT_PUBLIC_URL || 'https://example.com';
const ignoredPaths = ['/server-sitemap.xml', '/post'];
module.exports = {
siteUrl,
generateRobotsTxt: true,
robotsTxtOptions: {
// Add server-sitemap.xml to sitemap index and robots.txt.
additionalSitemaps: [`${siteUrl}/server-sitemap.xml`],
// Remove server-sitemap.xml from robots.txt to prevent duplicated entries
transformRobotsTxt: async (config, robotsTxt) =>
config.robotsTxtOptions.additionalSitemaps
.slice(1)
.reduce(
(res, item) => res.replace(`Sitemap: ${item}\n`, ''),
robotsTxt,
),
alternateRefs: [
{
href: `${siteUrl}/de`,
hreflang: 'de'
}
]
},
transform: (config, path) => {
// Remove entries from static sitemap which are contained in the server-sitemap.xml
if (ignoredPaths.some((dynamicPath) => path.startsWith(dynamicPath))) {
return null;
}
return {
loc: path,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
alternateRefs: config.alternateRefs ?? [],
};
},
};