mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
Added OUTPUT dir to sitemap build command (#8824)
This commit is contained in:
parent
11f45b9a32
commit
10b103820e
2 changed files with 13 additions and 7 deletions
5
.changeset/funny-deers-report.md
Normal file
5
.changeset/funny-deers-report.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/sitemap': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Display output directory in the sitemap build result
|
|
@ -1,5 +1,6 @@
|
||||||
import type { AstroConfig, AstroIntegration } from 'astro';
|
import type { AstroConfig, AstroIntegration } from 'astro';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import path from 'node:path';
|
||||||
import {
|
import {
|
||||||
EnumChangefreq,
|
EnumChangefreq,
|
||||||
simpleSitemapAndIndex,
|
simpleSitemapAndIndex,
|
||||||
|
@ -99,8 +100,8 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {
|
||||||
.map((p) => {
|
.map((p) => {
|
||||||
if (p.pathname !== '' && !finalSiteUrl.pathname.endsWith('/'))
|
if (p.pathname !== '' && !finalSiteUrl.pathname.endsWith('/'))
|
||||||
finalSiteUrl.pathname += '/';
|
finalSiteUrl.pathname += '/';
|
||||||
const path = finalSiteUrl.pathname + p.pathname;
|
const fullPath = finalSiteUrl.pathname + p.pathname;
|
||||||
return new URL(path, finalSiteUrl).href;
|
return new URL(fullPath, finalSiteUrl).href;
|
||||||
});
|
});
|
||||||
|
|
||||||
let routeUrls = routes.reduce<string[]>((urls, r) => {
|
let routeUrls = routes.reduce<string[]>((urls, r) => {
|
||||||
|
@ -116,9 +117,9 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {
|
||||||
* remove the initial slash from relative pathname
|
* remove the initial slash from relative pathname
|
||||||
* because `finalSiteUrl` always has trailing slash
|
* 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') {
|
if (config.trailingSlash === 'never') {
|
||||||
urls.push(newUrl);
|
urls.push(newUrl);
|
||||||
|
@ -169,15 +170,15 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const destDir = fileURLToPath(dir);
|
||||||
await simpleSitemapAndIndex({
|
await simpleSitemapAndIndex({
|
||||||
hostname: finalSiteUrl.href,
|
hostname: finalSiteUrl.href,
|
||||||
destinationDir: fileURLToPath(dir),
|
destinationDir: destDir,
|
||||||
sourceData: urlData,
|
sourceData: urlData,
|
||||||
limit: entryLimit,
|
limit: entryLimit,
|
||||||
gzip: false,
|
gzip: false,
|
||||||
});
|
});
|
||||||
logger.success(`\`${OUTFILE}\` is created.`);
|
logger.success(`\`${OUTFILE}\` created at \`${path.relative(process.cwd(), destDir)}\``);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof ZodError) {
|
if (err instanceof ZodError) {
|
||||||
logger.warn(formatConfigErrorMessage(err));
|
logger.warn(formatConfigErrorMessage(err));
|
||||||
|
|
Loading…
Add table
Reference in a new issue