From ca66da3e1cf45819ed5b4d4883b63e7a99161ad2 Mon Sep 17 00:00:00 2001 From: Adam McKerlie Date: Fri, 13 Oct 2023 08:08:45 -0400 Subject: [PATCH 1/4] Added OUTPUT dir to sitemap build command --- .changeset/funny-deers-report.md | 5 +++++ packages/integrations/sitemap/src/index.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/funny-deers-report.md diff --git a/.changeset/funny-deers-report.md b/.changeset/funny-deers-report.md new file mode 100644 index 000000000000..21726fd25238 --- /dev/null +++ b/.changeset/funny-deers-report.md @@ -0,0 +1,5 @@ +--- +'@astrojs/sitemap': patch +--- + +Added OUTPUT directory to the sitemap build command diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 2094aa3b193a..1e46a3cc2f4a 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -177,7 +177,7 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { limit: entryLimit, gzip: false, }); - logger.success(`\`${OUTFILE}\` is created.`); + logger.success(`\`${OUTFILE}\` created at \`${fileURLToPath(dir)}`); } catch (err) { if (err instanceof ZodError) { logger.warn(formatConfigErrorMessage(err)); From a06b5c6e9bc9253db3f7e8c6ef91dc618321531f Mon Sep 17 00:00:00 2001 From: Adam McKerlie Date: Fri, 13 Oct 2023 10:14:51 -0400 Subject: [PATCH 2/4] Show relative path for output destination --- packages/integrations/sitemap/src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 1e46a3cc2f4a..d6a55f36a797 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, @@ -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}\` created at \`${fileURLToPath(dir)}`); + logger.success(`\`${OUTFILE}\` created at \`${path.relative(process.cwd(), destDir)}\``); } catch (err) { if (err instanceof ZodError) { logger.warn(formatConfigErrorMessage(err)); From 33a4629bd6a18a3a7ed721152d9ae26c5f5973f3 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Fri, 13 Oct 2023 22:21:30 +0800 Subject: [PATCH 3/4] Update .changeset/funny-deers-report.md --- .changeset/funny-deers-report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/funny-deers-report.md b/.changeset/funny-deers-report.md index 21726fd25238..69a3eea261ce 100644 --- a/.changeset/funny-deers-report.md +++ b/.changeset/funny-deers-report.md @@ -2,4 +2,4 @@ '@astrojs/sitemap': patch --- -Added OUTPUT directory to the sitemap build command +Display output directory in the sitemap build result From f672224d222db8019ca4eb7d88fbbe6c82d37f55 Mon Sep 17 00:00:00 2001 From: Adam McKerlie Date: Fri, 13 Oct 2023 10:43:39 -0400 Subject: [PATCH 4/4] Fix variable conflict with import --- packages/integrations/sitemap/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index d6a55f36a797..571da4e588d0 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -100,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) => { @@ -117,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);