diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 70441cb8e..01759eaef 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -17,6 +17,16 @@ type SitemapOptions = */ filter?(page: string): string; + /** + * If you have any URL, not rendered by Astro, that you want to include in your sitemap, + * this config option will help you to include your array of custom pages in your sitemap. + * + * ```js + * customPages: ['http://example.com/custom-page', 'http://example.com/custom-page2'] + * ``` + */ + customPages?: Array; + /** * If present, we use the `site` config option as the base for all sitemap URLs * Use `canonicalURL` to override this @@ -40,6 +50,7 @@ function generateSitemap(pages: string[]) { export default function createPlugin({ filter, + customPages, canonicalURL, }: SitemapOptions = {}): AstroIntegration { let config: AstroConfig; @@ -61,6 +72,9 @@ export default function createPlugin({ if (filter) { pageUrls = pageUrls.filter((page: string) => filter(page)); } + if (customPages) { + pageUrls = [...pageUrls, ...customPages]; + } const sitemapContent = generateSitemap(pageUrls); fs.writeFileSync(new URL('sitemap.xml', dir), sitemapContent); },