@@ -47,14 +47,23 @@ const PKG_NAME = '@astrojs/sitemap';
47
47
const OUTFILE = 'sitemap-index.xml' ;
48
48
const STATUS_CODE_PAGES = new Set ( [ '404' , '500' ] ) ;
49
49
50
- function isStatusCodePage ( pathname : string ) : boolean {
51
- if ( pathname . endsWith ( '/' ) ) {
52
- pathname = pathname . slice ( 0 , - 1 ) ;
53
- }
54
- const end = pathname . split ( '/' ) . pop ( ) ?? '' ;
55
- return STATUS_CODE_PAGES . has ( end ) ;
56
- }
57
-
50
+ const isStatusCodePage = ( locales : string [ ] ) => {
51
+ const statusPathNames = new Set (
52
+ locales
53
+ . flatMap ( ( locale ) => [ ...STATUS_CODE_PAGES ] . map ( ( page ) => `${ locale } /${ page } ` ) )
54
+ . concat ( [ ...STATUS_CODE_PAGES ] )
55
+ ) ;
56
+
57
+ return ( pathname : string ) : boolean => {
58
+ if ( pathname . endsWith ( '/' ) ) {
59
+ pathname = pathname . slice ( 0 , - 1 ) ;
60
+ }
61
+ if ( pathname . startsWith ( '/' ) ) {
62
+ pathname = pathname . slice ( 1 ) ;
63
+ }
64
+ return statusPathNames . has ( pathname ) ;
65
+ } ;
66
+ } ;
58
67
const createPlugin = ( options ?: SitemapOptions ) : AstroIntegration => {
59
68
let config : AstroConfig ;
60
69
@@ -88,9 +97,9 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {
88
97
) ;
89
98
return ;
90
99
}
91
-
100
+ const shouldIgnoreStatus = isStatusCodePage ( Object . keys ( opts . i18n ?. locales ?? { } ) ) ;
92
101
let pageUrls = pages
93
- . filter ( ( p ) => ! isStatusCodePage ( p . pathname ) )
102
+ . filter ( ( p ) => ! shouldIgnoreStatus ( p . pathname ) )
94
103
. map ( ( p ) => {
95
104
if ( p . pathname !== '' && ! finalSiteUrl . pathname . endsWith ( '/' ) )
96
105
finalSiteUrl . pathname += '/' ;
@@ -107,7 +116,7 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {
107
116
* Dynamic URLs have entries with `undefined` pathnames
108
117
*/
109
118
if ( r . pathname ) {
110
- if ( isStatusCodePage ( r . pathname ?? r . route ) ) return urls ;
119
+ if ( shouldIgnoreStatus ( r . pathname ?? r . route ) ) return urls ;
111
120
112
121
// `finalSiteUrl` may end with a trailing slash
113
122
// or not because of base paths.
0 commit comments