[ci] format

This commit is contained in:
natemoo-re 2022-03-10 20:15:34 +00:00 committed by GitHub Actions
parent 10843aba63
commit 7b18d4c226
3 changed files with 6 additions and 4 deletions

View file

@ -243,7 +243,7 @@ export interface AstroUserConfig {
* }
* ```
*/
sitemapFilter?: (page: string) => boolean
sitemapFilter?: (page: string) => boolean;
/**
* @docs

View file

@ -150,7 +150,10 @@ class AstroBuilder {
if (this.config.buildOptions.sitemap && this.config.buildOptions.site) {
timer.sitemapStart = performance.now();
const sitemapFilter = this.config.buildOptions.sitemapFilter ? (this.config.buildOptions.sitemapFilter as (page: string) => boolean) : undefined;
const sitemap = generateSitemap(pageNames.map((pageName) => new URL(pageName, this.config.buildOptions.site).href), sitemapFilter);
const sitemap = generateSitemap(
pageNames.map((pageName) => new URL(pageName, this.config.buildOptions.site).href),
sitemapFilter
);
const sitemapPath = new URL('./sitemap.xml', this.config.dist);
await fs.promises.mkdir(new URL('./', sitemapPath), { recursive: true });
await fs.promises.writeFile(sitemapPath, sitemap, 'utf8');

View file

@ -1,4 +1,3 @@
const STATUS_CODE_PAGE_REGEXP = /\/[0-9]{3}\/?$/;
/** Construct sitemap.xml given a set of URLs */
@ -11,7 +10,7 @@ export function generateSitemap(pages: string[], filter?: (page: string) => bool
let urls = [...pages].filter((url) => !STATUS_CODE_PAGE_REGEXP.test(url));
if (filter) {
urls = urls.filter(url => filter(url));
urls = urls.filter((url) => filter(url));
}
urls.sort((a, b) => a.localeCompare(b, 'en', { numeric: true })); // sort alphabetically so sitemap is same each time