diff --git a/.changeset/funny-deers-report.md b/.changeset/funny-deers-report.md new file mode 100644 index 000000000000..69a3eea261ce --- /dev/null +++ b/.changeset/funny-deers-report.md @@ -0,0 +1,5 @@ +--- +'@astrojs/sitemap': patch +--- + +Display output directory in the sitemap build result diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 2094aa3b193a..571da4e588d0 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -1,5 +1,6 @@ import type { AstroConfig, AstroIntegration } from 'astro'; import { fileURLToPath } from 'node:url'; +import path from 'node:path'; import { EnumChangefreq, simpleSitemapAndIndex, @@ -99,8 +100,8 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { .map((p) => { if (p.pathname !== '' && !finalSiteUrl.pathname.endsWith('/')) finalSiteUrl.pathname += '/'; - const path = finalSiteUrl.pathname + p.pathname; - return new URL(path, finalSiteUrl).href; + const fullPath = finalSiteUrl.pathname + p.pathname; + return new URL(fullPath, finalSiteUrl).href; }); let routeUrls = routes.reduce((urls, r) => { @@ -116,9 +117,9 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { * remove the initial slash from relative pathname * because `finalSiteUrl` always has trailing slash */ - const path = finalSiteUrl.pathname + r.generate(r.pathname).substring(1); + const fullPath = finalSiteUrl.pathname + r.generate(r.pathname).substring(1); - let newUrl = new URL(path, finalSiteUrl).href; + let newUrl = new URL(fullPath, finalSiteUrl).href; if (config.trailingSlash === 'never') { urls.push(newUrl); @@ -169,15 +170,15 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { return; } } - + const destDir = fileURLToPath(dir); await simpleSitemapAndIndex({ hostname: finalSiteUrl.href, - destinationDir: fileURLToPath(dir), + destinationDir: destDir, sourceData: urlData, limit: entryLimit, gzip: false, }); - logger.success(`\`${OUTFILE}\` is created.`); + logger.success(`\`${OUTFILE}\` created at \`${path.relative(process.cwd(), destDir)}\``); } catch (err) { if (err instanceof ZodError) { logger.warn(formatConfigErrorMessage(err));