You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feature: add sitemap services, utils and parsers. add sitemap path to nextJS.
* refactor: update test cases
* refactor: update the function names, fix static sitemap generation
* refactor: revert logger test case fixes
* fix: NODE_ENV type
* feat: add time bases revalidation
* feat: keep time based revalidation to 0 so sitemaps are generated dynamically always
* refactor: remove duplicated deps, rename sitemap.config to sitemapConfig, explicitly mentioning exporting members from script
* chore: add link to sitemap() docblock
* refactor: config keys.
* refactor: replace @link annotation with @see
* refactor: replace export { generateSitemap } with function
* refactor: rename sitemap_index.xml to sitemap.xml, move SitemapDataFromXML from types package to types.ts
* refactor: remove types from @return and @param
* refactor: rename sitemap.xml to sitemap_index.xml because paths are conflicting
* refactor: rename sitemap_index.xml to wp-sitemap.xml
* doc: add sitemap.md doc and update config-api.md doc
* chore: add unit tests for the next sitemap module
* chore: update test cases for sitemap generation, wrap getSitemapPaths in try/catch block
* chore: npm run format
* chore: cleanup
* chore: npm run format
* chore: update docs
* docs: modify doc to make it more accurate
* docs: clarify `SitemapConfig.customPaths`
* fix: deep merge issue with sitemap
* doc: add link to the MetadataRoute.SiteMap interface
* chore: update docs format
* fix: test cases
* refactor: remove if-else-if ladder
---------
Co-authored-by: Dovid Levine <david@axepress.dev>
Copy file name to clipboardExpand all lines: docs/config-api.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,7 @@ Here are the available configuration options:
69
69
|`blockDefinitions`|`BlockDefinitions`|[blocks](../packages/blocks/src/blocks/index.ts)| Block definitions for the editor.<br />[Learn more](./overloading-wp-behavior.md#overloading-blocks)|
70
70
|`parserOptions`|`HTMLReactParserOptions`|[defaultOptions](../packages/next/src/react-parser/options.tsx)| The default options for the `html-react-parser` library.<br />[Learn more](./overloading-wp-behavior.md#2-pass-customparseroptions-to-overload)|
71
71
|`query`|`QueryEngine`|[ApolloClientEngine](../packages/plugin-apollo-client/src/engine/index.ts)| Configuration for the GraphQL query engine.<br />See below for more details on how to customize it.[Learn more](./query-engine.md)|
72
+
|`sitemap`|`SitemapConfig`| undefined | Configuration for the sitemap plugin.<br />[Learn more](./sitemap.md)|
72
73
73
74
Config values are available via their respective keys in the `getConfig()` function.
74
75
@@ -139,6 +140,16 @@ export default config;
139
140
140
141
This configuration allows you to replace the default engine with your custom engine. For more information about creating a custom query engine, see [Creating a Custom Query Engine](./query-engine.md#creating-a-custom-query-engine).
141
142
143
+
### `sitemap` Configuration
144
+
145
+
Sitemap behavior is controllable vis the `sitemap` configuration object. The following are the available options:
| `indexUri` | `string` | `/wp-sitemap.xml` | The URI of the WordPress index sitemap. |
150
+
| `ignorePatterns` | `string[]` | `undefined` | An array of regex patterns used to exclude specific URLs from the sitemap.<br /><br />**Important:** These patterns are matched against the WordPress URLs of each post or page — not your frontend (e.g., Next.js) URLs. For example, if your WordPress site is hosted at `https://example.com` and a post URL is `https://example.com/blog/my-post`, a pattern like `/\/blog\//` or `/my-post$/` will work, while `/localhost:3000/blog/my-post/` will not. |
151
+
| `customPaths` | `Record<string, SitemapData[]>` | `undefined` | Arrays of SitemapData, keyed to their sub-sitemap names. This allows you to add custom or overload WordPress-generated sub-sitemaps.<br /> <br />The keys should match the sub-sitemap names as defined in the WordPress sitemap index. For example, if the WordPress sub-sitemap URL you are overriding is `http://mysite.local/wp-sitemap-posts-page-1.xml`, the key should be `wp-sitemap-posts-page-1`.<br /> <br />The `SitemapData` is a subset of [NextJS's MetadataRoute.SiteMap](https://github.com/vercel/next.js/blob/47eda30f1ab5ff8fc97802643125b4ce19cac14e/packages/next/src/lib/metadata/types/metadata-interface.ts#L687). The `images` and `videos` properties are _not_ supported. |
152
+
142
153
## Integration with `next.config.ts`
143
154
144
155
SnapWP extends the Next.js configuration using the `withSnapWP`functionto configure certain settings automatically based on your Config API, such as using the WordPress URL for [`images.remotePatterns`](https://nextjs.org/docs/app/api-reference/components/image#remotepatterns).
By default, SnapWP uses WordPress's built-in sitemap as the source of truth for generating sitemaps. The sitemap is built using data fetched directly from your WordPress backend and updates automatically.
4
+
5
+
## Index Sitemap
6
+
7
+
In the example Next.js starter app, the main sitemap is available at `/wp-sitemap.xml`, just like WordPress default.
8
+
9
+
### How to Change the Index Sitemap Path in Next.js
10
+
11
+
If you'd like to change the path (e.g., to `/sitemap_index.xml`), follow these steps:
12
+
13
+
1. Create a directory in `app/` named `sitemap_index.xml`.
// This function returns an array of sitemap IDs from WordPress
52
+
exportconst generateSitemaps =async () => {
53
+
returnawaitgetSitemapPaths();
54
+
};
55
+
56
+
// This function generates the XML for each sitemap based on the ID
57
+
exportdefaultasyncfunction sitemap( { id }: { id:string } ) {
58
+
returnawaitgenerateSubSitemaps( id );
59
+
}
60
+
61
+
// Always render fresh sitemap content
62
+
exportconst revalidate =0;
63
+
```
64
+
65
+
### What Each Function Does
66
+
67
+
-**`getSitemapPaths()`** → Fetches all available sitemap IDs (e.g., `wp-sitemap-posts-post-1`, `wp-sitemap-pages-page-1`) from the WordPress sitemap index.
68
+
-**`generateSubSitemaps(id)`** → Generates the XML content for the specified sitemap ID by fetching the sub-sitemap and mapping the URLs.
69
+
-**`revalidate = 0`** → Disables static caching to ensure the sitemap is always generated fresh on every request.
0 commit comments