File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
1
const i18nConfig = require ( "./i18n.config.json" )
2
2
const locales = i18nConfig . map ( ( { code } ) => code )
3
3
4
+ const defaultLocale = "en"
5
+
4
6
/** @type {import('next-sitemap').IConfig } */
5
7
module . exports = {
6
8
siteUrl : process . env . SITE_URL || "https://ethereum.org" ,
7
9
generateRobotsTxt : true ,
8
10
transform : async ( _ , path ) => {
9
11
const rootPath = path . split ( "/" ) [ 1 ]
10
12
if ( path . endsWith ( "/404" ) ) return null
11
- const isDefaultLocale = ! locales . includes ( rootPath ) || rootPath === "en"
13
+ const isDefaultLocale =
14
+ ! locales . includes ( rootPath ) || rootPath === defaultLocale
15
+
16
+ // Strip default-locale (en) prefix from paths; drop the `/en` root entry
17
+ let loc = path
18
+ if ( rootPath === defaultLocale ) {
19
+ // Drop the `/en` root entry to avoid duplicating `/`
20
+ if ( path === `/${ defaultLocale } ` || path === `/${ defaultLocale } /` )
21
+ return null
22
+ const defaultLocalePrefix = new RegExp ( `^/${ defaultLocale } (/|$)` )
23
+ loc = path . replace ( defaultLocalePrefix , "/" )
24
+ }
25
+
12
26
return {
13
- loc : path ,
27
+ loc,
14
28
changefreq : isDefaultLocale ? "weekly" : "monthly" ,
15
29
priority : isDefaultLocale ? 0.7 : 0.5 ,
16
30
}
Original file line number Diff line number Diff line change @@ -50,7 +50,9 @@ export const addSlashes = (href: string): string => {
50
50
}
51
51
52
52
export const getFullUrl = ( locale : string | undefined , path : string ) =>
53
- addSlashes ( new URL ( join ( locale || DEFAULT_LOCALE , path ) , SITE_URL ) . href )
53
+ DEFAULT_LOCALE === locale || ! locale
54
+ ? addSlashes ( new URL ( path , SITE_URL ) . href )
55
+ : addSlashes ( new URL ( join ( locale , path ) , SITE_URL ) . href )
54
56
55
57
// Remove trailing slash from slug and add leading slash
56
58
export const normalizeSlug = ( slug : string ) => {
You can’t perform that action at this time.
0 commit comments