generated from 0ctanium/nextjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
next-sitemap.js
39 lines (35 loc) · 1.03 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
const {i18n} = require('./next-i18next.config');
require('@next/env').loadEnvConfig(
process.cwd(),
process.env.NODE_ENV === 'development'
);
module.exports = {
siteUrl: process.env.NEXT_PUBLIC_SITE_URL,
generateRobotsTxt: true,
sitemapSize: 7000,
exclude: ['/next/*'],
i18n: i18n,
transform: async (config, path) => {
const [, currentLocale] = path.split('/');
const isLocalized = i18n.locales.includes(currentLocale);
const pathWithoutLocate = isLocalized
? path.substring(currentLocale.length + 1)
: path;
return {
loc: path,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
'xhtml:link': i18n.locales
.map(
(locale) =>
(!isLocalized || currentLocale !== locale) && {
rel: 'alternate',
hreflang: locale,
href: `${config.siteUrl}/${locale}${pathWithoutLocate}`,
}
)
.filter(Boolean),
};
},
};