11import path from 'node:path' ;
22import { fileURLToPath } from 'node:url' ;
3- import type { AstroConfig , AstroIntegration } from 'astro' ;
3+ import type { AstroConfig , AstroIntegration , IntegrationResolvedRoute } from 'astro' ;
44import type { EnumChangefreq , LinkItem as LinkItemBase , SitemapItemLoose } from 'sitemap' ;
55import { ZodError } from 'zod' ;
66
@@ -76,17 +76,22 @@ const isStatusCodePage = (locales: string[]) => {
7676 } ;
7777} ;
7878const createPlugin = ( options ?: SitemapOptions ) : AstroIntegration => {
79+ let _routes : Array < IntegrationResolvedRoute > ;
7980 let config : AstroConfig ;
8081
8182 return {
8283 name : PKG_NAME ,
8384
8485 hooks : {
86+ 'astro:routes:resolved' : ( { routes } ) => {
87+ _routes = routes ;
88+ } ,
89+
8590 'astro:config:done' : async ( { config : cfg } ) => {
8691 config = cfg ;
8792 } ,
8893
89- 'astro:build:done' : async ( { dir, routes , pages, logger } ) => {
94+ 'astro:build:done' : async ( { dir, pages, logger } ) => {
9095 try {
9196 if ( ! config . site ) {
9297 logger . warn (
@@ -112,15 +117,15 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {
112117 return new URL ( fullPath , finalSiteUrl ) . href ;
113118 } ) ;
114119
115- const routeUrls = routes . reduce < string [ ] > ( ( urls , r ) => {
120+ const routeUrls = _routes . reduce < string [ ] > ( ( urls , r ) => {
116121 // Only expose pages, not endpoints or redirects
117122 if ( r . type !== 'page' ) return urls ;
118123
119124 /**
120125 * Dynamic URLs have entries with `undefined` pathnames
121126 */
122127 if ( r . pathname ) {
123- if ( shouldIgnoreStatus ( r . pathname ?? r . route ) ) return urls ;
128+ if ( shouldIgnoreStatus ( r . pathname ?? r . pattern ) ) return urls ;
124129
125130 // `finalSiteUrl` may end with a trailing slash
126131 // or not because of base paths.
0 commit comments