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
Copy file name to clipboardExpand all lines: docs/explanation/sitemaps.md
+12-20Lines changed: 12 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,34 +75,25 @@ This route will serve the WordPress `sitemap.xml` in your Next.js application dy
75
75
76
76
2.**Generating a Sitemap from GraphQL Content**
77
77
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).
79
79
80
80
Example implementation using Next.js and WPGraphQL:
81
81
82
82
```javascript
83
83
import { gql } from'@apollo/client';
84
84
import { client } from'../lib/apolloClient';
85
85
86
+
// Function to fetch all posts from WordPress
87
+
asyncfunctionfetchAllPosts() {}
88
+
89
+
// Similar function for pages
90
+
asyncfunctionfetchAllPages() {}
91
+
86
92
exportasyncfunctiongenerateSitemap() {
87
-
const { data } =awaitclient.query({
88
-
query:gql`
89
-
queryGetAllContent {
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
-
// Addothercustomposttypesasneeded
103
-
}
104
-
`,
105
-
});
93
+
const [posts, pages] =awaitPromise.all([
94
+
fetchAllPosts(),
95
+
fetchAllPages(),
96
+
]);
106
97
constallContent= [
107
98
...data.posts.nodes.map(post=> ({
108
99
slug:`posts/${post.slug}`,
@@ -158,6 +149,7 @@ export async function GET() {
158
149
* Requires manual updates to include new content types or custom routes
159
150
* May require pagination handling for large sites
160
151
* Doesn't leverage WordPress SEO plugin sitemap enhancements
152
+
* Increasing the GraphQL limits may cause performance issues on resource-constrained WordPress instances.
161
153
162
154
3.**Hybrid Approach: Fetching, Parsing, and Enhancing Existing Sitemaps**
0 commit comments