diff options
author | 2023-10-17 10:44:15 -0400 | |
---|---|---|
committer | 2023-10-17 22:44:15 +0800 | |
commit | 10b103820e22e51dcfb0592c542cdf2c5eeb2f52 (patch) | |
tree | 0e1493e227e87ec9175ad2f10288862b9ec6f290 | |
parent | 11f45b9a3216f60317e1c54bb3e6c4e9e0add342 (diff) | |
download | astro-10b103820e22e51dcfb0592c542cdf2c5eeb2f52.tar.gz astro-10b103820e22e51dcfb0592c542cdf2c5eeb2f52.tar.zst astro-10b103820e22e51dcfb0592c542cdf2c5eeb2f52.zip |
Added OUTPUT dir to sitemap build command (#8824)
-rw-r--r-- | .changeset/funny-deers-report.md | 5 | ||||
-rw-r--r-- | packages/integrations/sitemap/src/index.ts | 15 |
2 files changed, 13 insertions, 7 deletions
diff --git a/.changeset/funny-deers-report.md b/.changeset/funny-deers-report.md new file mode 100644 index 000000000..69a3eea26 --- /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 2094aa3b1..571da4e58 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<string[]>((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)); |