Skip to content

Commit dd06779

Browse files
chore(sitemap): migrate to astro:routes:resolved (#15033)
1 parent 8115752 commit dd06779

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.changeset/icy-pigs-smile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/sitemap': patch
3+
---
4+
5+
Updates how routes are retrieved to avoid relying on a deprecated API

packages/integrations/sitemap/src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path';
22
import { fileURLToPath } from 'node:url';
3-
import type { AstroConfig, AstroIntegration } from 'astro';
3+
import type { AstroConfig, AstroIntegration, IntegrationResolvedRoute } from 'astro';
44
import type { EnumChangefreq, LinkItem as LinkItemBase, SitemapItemLoose } from 'sitemap';
55
import { ZodError } from 'zod';
66

@@ -76,17 +76,22 @@ const isStatusCodePage = (locales: string[]) => {
7676
};
7777
};
7878
const 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

Comments
 (0)