@@ -34,6 +34,7 @@ export interface NuxtPagesToSitemapEntriesOptions {
34
34
defaultLocale : string
35
35
strategy : 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default'
36
36
isI18nMapped : boolean
37
+ isI18nMicro : boolean
37
38
filter : CreateFilterOptions
38
39
}
39
40
@@ -46,18 +47,41 @@ interface PageEntry extends SitemapUrl {
46
47
function deepForEachPage (
47
48
pages : NuxtPage [ ] ,
48
49
callback : ( page : NuxtPage , fullpath : string , depth : number ) => void ,
50
+ opts : NuxtPagesToSitemapEntriesOptions ,
49
51
fullpath : string | undefined | null = null ,
50
52
depth : number = 0 ,
51
53
) {
52
- pages . forEach ( ( page : NuxtPage ) => {
53
- let currentPath : string | null
54
- if ( page . path . startsWith ( '/' ) )
54
+ pages . forEach ( ( page ) => {
55
+ let currentPath
56
+ if ( page . path . startsWith ( '/' ) ) {
55
57
currentPath = page . path
56
- else
58
+ }
59
+ else {
57
60
currentPath = page . path === '' ? fullpath : `${ fullpath ! . replace ( / \/ $ / , '' ) } /${ page . path } `
58
- callback ( page , currentPath || '' , depth )
59
- if ( page . children )
60
- deepForEachPage ( page . children , callback , currentPath , depth + 1 )
61
+ }
62
+
63
+ let didCallback = false
64
+ if ( opts . isI18nMicro ) {
65
+ const localePattern = / \/ : l o c a l e \( ( [ ^ ) ] + ) \) /
66
+ const match = localePattern . exec ( currentPath || '' )
67
+ if ( match ) {
68
+ const locales = match [ 1 ] . split ( '|' )
69
+ locales . forEach ( ( locale ) => {
70
+ const subPage = { ...page }
71
+ const localizedPath = ( currentPath || '' ) . replace ( localePattern , `/${ locale } ` )
72
+ subPage . name += opts . routesNameSeparator + locale
73
+ subPage . path = localizedPath
74
+ callback ( subPage , localizedPath || '' , depth )
75
+ didCallback = true
76
+ } )
77
+ }
78
+ }
79
+ if ( ! didCallback ) {
80
+ callback ( page , currentPath || '' , depth )
81
+ }
82
+ if ( page . children ) {
83
+ deepForEachPage ( page . children , callback , opts , currentPath , depth + 1 )
84
+ }
61
85
} )
62
86
}
63
87
@@ -70,6 +94,10 @@ export function convertNuxtPagesToSitemapEntries(pages: NuxtPage[], config: Nuxt
70
94
( page , loc , depth ) => {
71
95
flattenedPages . push ( { page, loc, depth } )
72
96
} ,
97
+ {
98
+ ...config ,
99
+ routesNameSeparator : config . routesNameSeparator || '___' ,
100
+ } ,
73
101
)
74
102
flattenedPages = flattenedPages
75
103
// Removing dynamic routes
0 commit comments