From ea104dde910b8a530c134c30bc522c9f13fd3dac Mon Sep 17 00:00:00 2001 From: Eloi-Perez <37666229+Eloi-Perez@users.noreply.github.com> Date: Thu, 12 May 2022 21:19:58 +0100 Subject: [PATCH] Add config option customPages (#3315) * Add config option customPages Add config option customPages to be able to add custom URL pages to the sitemap.xml * add comment to document customPages option --- packages/integrations/sitemap/src/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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); },