Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OUTPUT dir to sitemap build command #8824

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-deers-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/sitemap': patch
---

Display output directory in the sitemap build result
15 changes: 8 additions & 7 deletions packages/integrations/sitemap/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { AstroConfig, AstroIntegration } from 'astro';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import {
EnumChangefreq,
simpleSitemapAndIndex,
Expand Down Expand Up @@ -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) => {
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
Loading