-
Notifications
You must be signed in to change notification settings - Fork 2
docs: Create a custom WordPress sitemap with custom WP-GQL endpoint #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
colinmurphy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahuseyn 🚀 🚀 🚀
LGTM.
Just want to call out and say this is very impressive. The sitemaps look good to me.
I also validated them with xmllint
e.g.
xmllint --noout --debug http://localhost:3000/sitemap/posts/post/1.xml
xmllint --noout --debug http://localhost:3000/sitemap.xml |
Thanks @colinmurphy, I appreciate it 🙂 |
|
Looking good, I think we still need to decide how to address what was expected for this ticket vs this approach. Let's talk tomorrow during refinement. |
moonmeister
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm approving this for general acceptance criteria and content. I have not actually tested and run the code. I think this looks good. I'm debating whether we should have the catch-all route. given this is only suppose to be demonstrating sitemaps, do we ned to render pages? IS it a distraction? but also a front-end with no actual content is kinda weird. I'll leave it to you.
|
@moonmeister I gave a thought to rendering pages, and experimented with/without it. Without rendering pages the example looked incomplete/partial as the final sitemap links were breaking. Thus I wanted to add a single catch-all route to minimize the distraction. |
Related to: #30
The example includes the @colinmurphy's implementation of wp-env, with custom data and plugins
Which parts need focused attention?
hwpt-wpgraphql-sitemap needs focused attention
Overview
This example demonstrates how to generate a custom sitemap in a headless WordPress application using the Next.js framework. The example app fetches data from WordPress using Apollo Client and WPGraphQL. Since WPGraphQL doesn't support sitemaps natively, we are extending it with a custom plugin, which is included in this example as well. This plugin exposes new fields to fetch the sitemap index, with data identical to what's rendered on the native WordPress sitemap. Another field exposed by this plugin allows you to request sitemap subpages by specifying the types and pages. The plugin also adds featured image data, enabling you to create Image Sitemaps.
The example includes a wp-env setup, which will allow you to build and start this example quickly. With this wp-env setup, you don't need to have a separate WordPress instance or demo data to inspect the example.
Features
/sitemaprequests to/sitemap.xml, in thenext.config.mjsScreenshots
After following the installation steps, you should have the example sitemap pages as shown in the screenshots below:
Sitemap index
Posts
Categories
Tags
Users
Pages
Custom post type
Custom taxonomy type
Project Structure
Important notes
Discourage search engines from indexing this sitecheckbox underSettings -> Readingin the WordPress admin.Running the example with wp-env
Prerequisites
Note Please make sure you have all prerequisites installed as mentioned above and Docker running (
docker ps)Setup Repository and Packages
git clone https://github.com/wpengine/hwptoolkit.gitexamples/next/custom-sitemap-apollo/example-appand add these values inside:or run the command below:
Build and start the application
cd examples/next/custom-sitemap-apollopnpm example:buildwill build and start your application.wp-env/uploads.ziptowp-env/uploadswhich is mapped to the wp-content/uploads directory for the Docker container.example-appCongratulations, WordPress should now be fully set up.
Command Reference
example:buildexample:devexample:dev:installexample:startexample:stopexample:prunewp:startwp:stopwp:destroywp:db:querywp:db:exportwp-env/db/database.sql.wp:db:importwp-env/db/database.sql.wp:images:unzipwp:images:zipDatabase access
If you need database access add the following to your wp-env
"phpmyadminPort": 11111,(where port 11111 is not allocated).You can check if a port is free by running
lsof -i :11111