Skip to content

Commit

Permalink
Merge branch 'main' into feat/toolbar-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored Feb 21, 2024
2 parents d7a316e + 891c26e commit d241e03
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 103 deletions.
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.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
run: pnpm run lint

- name: Format Check
run: pnpm run format --check
run: pnpm run format:ci

test:
name: "Test: ${{ matrix.os }} (node@${{ matrix.NODE_VERSION }})"
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
"build:examples": "turbo run build --filter=\"@example/*\"",
"dev": "turbo run dev --concurrency=40 --parallel --filter=astro --filter=create-astro --filter=\"@astrojs/*\" --filter=\"@benchmark/*\"",
"format": "pnpm run format:code && pnpm run format:imports",
"format:ci": "pnpm run format:code && pnpm run format:imports",
"format:ci": "pnpm run format:code:check && pnpm run format:imports:check",
"format:code": "prettier -w \"**/*\" --ignore-unknown --cache",
"format:code:check": "prettier -w \"**/*\" --ignore-unknown --cache --check",
"format:imports": "biome check --apply .",
"format:imports:check": "biome ci .",
"test": "turbo run test --concurrency=1 --filter=astro --filter=create-astro --filter=\"@astrojs/*\"",
"test:match": "cd packages/astro && pnpm run test:match",
"test:unit": "cd packages/astro && pnpm run test:unit",
Expand Down
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.

0 comments on commit d241e03

Please sign in to comment.