Skip to content
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
7 changes: 7 additions & 0 deletions .changeset/slow-cats-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@astrojs/sitemap": patch
---

Revert https://github.com/withastro/astro/pull/9846

The feature to customize the file name of the sitemap was reverted due to some internal issues with one of the dependencies. With an non-deterministic behaviour, the sitemap file was sometime emitted with incorrect syntax.
31 changes: 9 additions & 22 deletions packages/integrations/sitemap/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type { AstroConfig, AstroIntegration } from 'astro';
import path, { resolve } from 'node:path';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import type { EnumChangefreq, LinkItem as LinkItemBase, SitemapItemLoose } from 'sitemap';
import { SitemapAndIndexStream, SitemapStream, streamToPromise } from 'sitemap';
import { simpleSitemapAndIndex } from 'sitemap';
import { ZodError } from 'zod';

import { generateSitemap } from './generate-sitemap.js';
import { validateOptions } from './validate-options.js';
import { createWriteStream } from 'node:fs';
import { Readable } from 'node:stream';

export { EnumChangefreq as ChangeFreqEnum } from 'sitemap';
export type ChangeFreq = `${EnumChangefreq}`;
Expand All @@ -35,8 +33,6 @@ export type SitemapOptions =
lastmod?: Date;
priority?: number;

prefix?: string;

// called for each sitemap item just before to save them on disk, sync or async
serialize?(item: SitemapItem): SitemapItem | Promise<SitemapItem | undefined> | undefined;
}
Expand All @@ -48,6 +44,7 @@ function formatConfigErrorMessage(err: ZodError) {
}

const PKG_NAME = '@astrojs/sitemap';
const OUTFILE = 'sitemap-index.xml';
const STATUS_CODE_PAGES = new Set(['404', '500']);

function isStatusCodePage(pathname: string): boolean {
Expand Down Expand Up @@ -80,8 +77,7 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {

const opts = validateOptions(config.site, options);

const { filter, customPages, serialize, entryLimit, prefix = 'sitemap-' } = opts;
const OUTFILE = `${prefix}index.xml`;
const { filter, customPages, serialize, entryLimit } = opts;

let finalSiteUrl: URL;
if (config.site) {
Expand Down Expand Up @@ -171,22 +167,13 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {
}
}
const destDir = fileURLToPath(dir);

const sms = new SitemapAndIndexStream({
await simpleSitemapAndIndex({
hostname: finalSiteUrl.href,
destinationDir: destDir,
sourceData: urlData,
limit: entryLimit,
getSitemapStream: (i) => {
const sitemapStream = new SitemapStream({ hostname: finalSiteUrl.href });
const fileName = `${prefix}${i}.xml`;

const ws = sitemapStream.pipe(createWriteStream(resolve(destDir + fileName)));

return [new URL(fileName, finalSiteUrl.href).toString(), sitemapStream, ws];
},
gzip: false,
});

sms.pipe(createWriteStream(resolve(destDir + OUTFILE)));
await streamToPromise(Readable.from(urlData).pipe(sms));
sms.end();
logger.info(`\`${OUTFILE}\` created at \`${path.relative(process.cwd(), destDir)}\``);
} catch (err) {
if (err instanceof ZodError) {
Expand Down
7 changes: 0 additions & 7 deletions packages/integrations/sitemap/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ export const SitemapOptionsSchema = z
changefreq: z.nativeEnum(ChangeFreq).optional(),
lastmod: z.date().optional(),
priority: z.number().min(0).max(1).optional(),

prefix: z
.string()
.regex(/^[a-zA-Z\-_]+$/gm, {
message: 'Only English alphabet symbols, hyphen and underscore allowed',
})
.optional(),
})
.strict()
.default(SITEMAP_CONFIG_DEFAULTS);
72 changes: 0 additions & 72 deletions packages/integrations/sitemap/test/prefix.test.js

This file was deleted.