Skip to content

Commit 2f32abd

Browse files
committed
chore: pr review update
1 parent 9eea41e commit 2f32abd

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

docs/explanation/sitemaps.md

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,25 @@ This route will serve the WordPress `sitemap.xml` in your Next.js application dy
7575

7676
2. **Generating a Sitemap from GraphQL Content**
7777

78-
Approach: This approach involves fetching content via GraphQL and generating a custom sitemap. This can be implemented using either server-side rendering (SSR) or static generation strategies.
78+
Approach: This approach involves fetching all available post and page info via GraphQL and generating a custom sitemap. This can be implemented using either server-side rendering (SSR) or static generation strategies. However since, WPGraphQL returns maximum 100 node per page trying to fetch all available post or pages on a large site might be problematic and slow. See [pagination limits in wp-graphql](https://www.wpgraphql.com/docs/known-limitations#pagination-limits).
7979

8080
Example implementation using Next.js and WPGraphQL:
8181

8282
```javascript
8383
import { gql } from '@apollo/client';
8484
import { client } from '../lib/apolloClient';
8585

86+
// Function to fetch all posts from WordPress
87+
async function fetchAllPosts() {}
88+
89+
// Similar function for pages
90+
async function fetchAllPages() {}
91+
8692
export async function generateSitemap() {
87-
const { data } = await client.query({
88-
query: gql`
89-
query GetAllContent {
90-
posts(first: 1000) {
91-
nodes {
92-
slug
93-
modified
94-
}
95-
}
96-
pages(first: 1000) {
97-
nodes {
98-
slug
99-
modified
100-
}
101-
}
102-
// Add other custom post types as needed
103-
}
104-
`,
105-
});
93+
const [posts, pages] = await Promise.all([
94+
fetchAllPosts(),
95+
fetchAllPages(),
96+
]);
10697
const allContent = [
10798
...data.posts.nodes.map(post => ({
10899
slug: `posts/${post.slug}`,
@@ -158,6 +149,7 @@ export async function GET() {
158149
* Requires manual updates to include new content types or custom routes
159150
* May require pagination handling for large sites
160151
* Doesn't leverage WordPress SEO plugin sitemap enhancements
152+
* Increasing the GraphQL limits may cause performance issues on resource-constrained WordPress instances.
161153

162154
3. **Hybrid Approach: Fetching, Parsing, and Enhancing Existing Sitemaps**
163155

0 commit comments

Comments
 (0)