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:
parent
8685506174
commit
ea104dde91
1 changed files with 14 additions and 0 deletions
|
@ -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);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue