From 3f8ee70e2bc5b49c65a0444d9606232dadbc2fca Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Thu, 23 Jun 2022 11:31:54 -0400 Subject: [PATCH] Fix: document sitemap + SSR use case (#3689) * fix: offer suggestion for SSR sitemap users * docs: add customPages to README * chore: changeset --- .changeset/sixty-mirrors-bake.md | 5 +++++ packages/integrations/sitemap/README.md | 21 +++++++++++++++++++++ packages/integrations/sitemap/src/index.ts | 7 ++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .changeset/sixty-mirrors-bake.md diff --git a/.changeset/sixty-mirrors-bake.md b/.changeset/sixty-mirrors-bake.md new file mode 100644 index 0000000000..db6a70bc41 --- /dev/null +++ b/.changeset/sixty-mirrors-bake.md @@ -0,0 +1,5 @@ +--- +'@astrojs/sitemap': patch +--- + +Add warning log for sitemap + SSR adapter, with suggestion to use customPages configuration option diff --git a/packages/integrations/sitemap/README.md b/packages/integrations/sitemap/README.md index fda6577e85..a2e7b73d9a 100644 --- a/packages/integrations/sitemap/README.md +++ b/packages/integrations/sitemap/README.md @@ -119,6 +119,27 @@ export default { The `page` function parameter is the full URL of your rendered page, including your `site` domain. Return `true` to include a page in your sitemap, and `false` to remove it. +### customPages + +You may have custom routes to add to your sitemap. To append these to your sitemap, pass an array of valid URLs including the base origin: + +__astro.config.mjs__ + +```js +import sitemap from '@astrojs/sitemap'; + +export default { + site: 'https://stargazers.club', + integrations: [ + sitemap({ + customPages: ['https://stargazers.biz/careers'], + }), + ], +} +``` + +💡 You should also use `customPages` to manually list sitemap pages when using an SSR adapter. Currently, we cannot detect your site's pages unless you are building statically. To avoid an empty sitemap, list all pages (including the base origin) with this configuration option! + ### canonicalURL If present, we use the `site` config option as the base for all sitemap URLs. Use `canonicalURL` to override this. diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index b9df1b0fc1..d18c9daea4 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -99,7 +99,12 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { } if (pageUrls.length === 0) { - logger.warn(`No data for sitemap.\n\`${OUTFILE}\` is not created.`); + // offer suggestion for SSR users + if (typeof config.adapter !== 'undefined') { + logger.warn(`No pages found! We can only detect sitemap routes for "static" projects. Since you are using an SSR adapter, we recommend manually listing your sitemap routes using the "customPages" integration option.\n\nExample: \`sitemap({ customPages: ['https://example.com/route'] })\``); + } else { + logger.warn(`No pages found!\n\`${OUTFILE}\` not created.`); + } return; }