-
-
Notifications
You must be signed in to change notification settings - Fork 240
/
next-sitemap.config.js
74 lines (69 loc) · 2.17 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const SITE_URL = 'https://revoke.cash';
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: SITE_URL,
generateIndexSitemap: false,
alternateRefs: [
{
href: SITE_URL,
hreflang: 'x-default',
},
{
href: SITE_URL,
hreflang: 'en',
},
{
href: `${SITE_URL}/zh`,
hreflang: 'zh',
},
{
href: `${SITE_URL}/ru`,
hreflang: 'ru',
},
{
href: `${SITE_URL}/ja`,
hreflang: 'ja',
},
{
href: `${SITE_URL}/es`,
hreflang: 'es',
},
],
exclude: [
// 404 pages should not be in the sitemap
'/**404',
// Images and static files should not be in the sitemap
'**/og.jpg/**',
'**.jpg',
'**.png',
'**.json',
'**.txt',
],
// Custom transform function to de-duplicate path locale strings in alternateRefs
// Without this we get things like https://<domain>/es/es/about rather than https://<domain>/es/about
// NOTE: This is made to work for path-based localisation scheme (https://<domain>/<locale>/<path>). It may not
// work if you're using subdomains or separate domains for localisation.
transform: async (config, originalPath) => {
// Remove the leading /en/ from the default path (added for i18n in App Router + next-intl)
const path = `${originalPath}/`.replace(/^\/en\//, '/').replace(/\/+$/, '');
// Remove the locale part of the path (e.g. /es/about -> /about)
const extractLocaleIndependentPath = (path) => {
const matches = config.alternateRefs.map((alt) =>
`${config.siteUrl}${path}/`.replace(`${alt.href}/`, '/').replace(/\/+$/, ''),
);
return matches.sort((a, b) => a.length - b.length)[0];
};
const localeIndependentPath = extractLocaleIndependentPath(path);
// Map the locale independent path onto the locale paths
const alternateRefs = config.alternateRefs.map((alt) => {
return { ...alt, href: `${alt.href}${localeIndependentPath}`, hrefIsAbsolute: true };
});
return {
loc: path,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
alternateRefs,
};
},
};