summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Eloi-Perez <37666229+Eloi-Perez@users.noreply.github.com> 2022-05-12 21:19:58 +0100
committerGravatar GitHub <noreply@github.com> 2022-05-12 14:19:58 -0600
commitea104dde910b8a530c134c30bc522c9f13fd3dac (patch)
tree3e4301a09f70fa51ef7c5a05d8b1b3644991b3d3
parent8685506174962329fb7a76367ea3cf32ea0aa48c (diff)
downloadastro-ea104dde910b8a530c134c30bc522c9f13fd3dac.tar.gz
astro-ea104dde910b8a530c134c30bc522c9f13fd3dac.tar.zst
astro-ea104dde910b8a530c134c30bc522c9f13fd3dac.zip
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
-rw-r--r--packages/integrations/sitemap/src/index.ts14
1 files changed, 14 insertions, 0 deletions
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
@@ -18,6 +18,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<string>;
+
+ /**
* 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);
},