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
This commit is contained in:
Eloi-Perez 2022-05-12 21:19:58 +01:00 committed by GitHub
parent 8685506174
commit ea104dde91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<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);
},