Skip to content

Commit

Permalink
Fix: document sitemap + SSR use case (#3689)
Browse files Browse the repository at this point in the history
* fix: offer suggestion for SSR sitemap users

* docs: add customPages to README

* chore: changeset
  • Loading branch information
bholmesdev authored Jun 23, 2022
1 parent 059d00b commit 3f8ee70
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sixty-mirrors-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/sitemap': patch
---

Add warning log for sitemap + SSR adapter, with suggestion to use customPages configuration option
21 changes: 21 additions & 0 deletions packages/integrations/sitemap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion packages/integrations/sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3f8ee70

Please sign in to comment.