Skip to content

Commit 9f688b1

Browse files
authored
Merge pull request #480 from wpengine/chore-move-and-validate-logging-docs
chore: Move and rewrite WPGraphQL Logging Docs
2 parents 17b596b + 57f2454 commit 9f688b1

File tree

69 files changed

+2795
-1935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2795
-1935
lines changed

.remarkrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"plugins": [
3+
"remark-frontmatter",
4+
"remark-gfm",
5+
"remark-preset-lint-recommended"
6+
],
7+
"settings": {
8+
"linkReference": false
9+
}
10+
}

docs/README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
# HWP Toolkit Documentation
1+
---
2+
title: "Documentation"
3+
description: "Documentation for the Headless WordPress Toolkit, a modern, framework-agnostic collection of plugins and packages for building headless WordPress applications."
4+
---
5+
6+
7+
## WPGraphQL Logging Plugin
8+
9+
| Title | Description |
10+
|------------------------------------|------------------------------|
11+
| [WPGraphQL Logging Plugin](plugins/wpgraphql-logging/) | Logging for WPGraphQL requests with granular lifecycle events and Monolog integration. |
12+
213

314

415
## Explanation Documentation
516

617
| Title | Description |
718
|------------------------------------|------------------------------|
8-
| [GET vs POST](explanation/get-vs-post.md) | Explanation on choosing between GET and POST methods for WPGraphQL requests. |
9-
| [GraphQL Endpoints](explanation/graphql-endpoints.md) | Documentation on differences between using /graphql or ?graphql for WPGraphQL endpoint. |
10-
| [Headless Authentication](explanation/headless-authentication.md) | Overview of user authentication and access control in a decoupled WordPress architecture. |
11-
| [Rendering Options](explanation/rendering-options.md) | A document that explores the various approaches to rendering content from a headless WordPress installation. |
12-
| [Routing](explanation/routing.md) | A comprehensive explanation on routing in a headless WordPress application. |
13-
| [Sitemaps](explanation/sitemaps.md) | A comprehensive explanation on sitemaps in a headless WordPress application. |
19+
| [GET vs POST](explanation/get-vs-post/index.md) | Explanation on choosing between GET and POST methods for WPGraphQL requests. |
20+
| [GraphQL Endpoints](explanation/graphql-endpoints/index.md) | Documentation on differences between using /graphql or ?graphql for WPGraphQL endpoint. |
21+
| [Headless Authentication](explanation/headless-authentication/index.md) | Overview of user authentication and access control in a decoupled WordPress architecture. |
22+
| [Rendering Options](explanation/rendering-options/index.md) | A document that explores the various approaches to rendering content from a headless WordPress installation. |
23+
| [Routing](explanation/routing/index.md) | A comprehensive explanation on routing in a headless WordPress application. |
24+
| [Sitemaps](explanation/sitemaps/index.md) | A comprehensive explanation on sitemaps in a headless WordPress application. |
1425

1526

1627
## How To Documentation
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "GET vs POST in WPGraphQL"
33
description: "A guide on the differences between using a GET request with a query parameter versus a POST request to the /graphql endpoint."
44
---
55

6-
# GET vs POST in WPGraphQL
6+
## Overview
77

88
When interacting with WPGraphQL, selecting the correct HTTP method to fetch data is crucial. This guide explains the differences between using a GET request with a query parameter versus a POST request to the /graphql endpoint.
99

@@ -52,3 +52,7 @@ curl -X POST \
5252

5353
# Summary
5454
While both methods have their uses, POST requests are generally recommended for WPGraphQL due to their flexibility, security advantages, and ability to handle complex queries. However, GET requests can be useful for simple, cacheable queries and is useful when paired with caching mechanisms like the Smart Cache plugin. Consider your specific use case, security requirements, and caching needs when choosing between the two methods.
55+
56+
## Contributing
57+
58+
If you feel like something is missing or you want to add documentation, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.

docs/explanation/graphql-endpoints.md renamed to docs/explanation/graphql-endpoints/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ add_filter( 'graphql_endpoint', 'my_new_graphql_endpoint' );
4242
```
4343
This code would change the default `/graphql` endpoint to `/my_endpoint`.
4444

45-
Alternatively, you can configure the endpoint directly in the **WPGraphQL Settings** under **GraphQL Endpoint**, without needing to modify your code.
45+
Alternatively, you can configure the endpoint directly in the **WPGraphQL Settings** under **GraphQL Endpoint**, without needing to modify your code.
46+
47+
## Contributing
48+
49+
If you feel like something is missing or you want to add documentation, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.

docs/explanation/headless-authentication.md renamed to docs/explanation/headless-authentication/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,8 @@ To tie everything together, we will provide:
104104
Our approach to authentication in headless WordPress emphasizes **modularity**, **security**, and developer **experience**. To support these principles, we will provide **ready-to-use code snippets** and **example boilerplate code** that you can easily integrate into your application.
105105

106106
## Example use case
107-
For example, if you're building a headless WordPress application with a React frontend, you can use our code snippets to implement Credentials authentication. You can integrate our boilerplate code for handling access tokens securely, including token storage and refresh logic, without needing to install additional dependencies.
107+
For example, if you're building a headless WordPress application with a React frontend, you can use our code snippets to implement Credentials authentication. You can integrate our boilerplate code for handling access tokens securely, including token storage and refresh logic, without needing to install additional dependencies.
108+
109+
## Contributing
110+
111+
If you feel like something is missing or you want to add documentation, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.

docs/explanation/rendering-options.md renamed to docs/explanation/rendering-options/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ title: "Headless WordPress Rendering Options"
33
description: "A guide that explores the various approaches to rendering content from a headless WordPress installation, their trade-offs, and best practices."
44
---
55

6-
# Headless WordPress Rendering Options
76
## Introduction
87

98
This document explores the various approaches to rendering content from a headless WordPress installation. As a front-end developer working with headless WordPress, you'll need to make important decisions about how to handle and display WordPress content in your frontend application. This guide aims to help you understand the available options, their trade-offs, and best practices.
@@ -142,3 +141,7 @@ Considerations
142141
* Styling Parity: Achieving perfect styling parity can be challenging due to the dynamic nature of WordPress styles.
143142

144143
* Maintenance: Styles may change with theme updates, customizations or major WordPress updates, requiring periodic updates in your headless application.
144+
145+
## Contributing
146+
147+
If you feel like something is missing or you want to add documentation, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,7 @@ In traditional WordPress, custom post types (CPTs) are registered using `registe
469469
470470
- `/portfolio/` → Archive page for portfolio items
471471
- `/portfolio/project-name/` → Single portfolio item
472+
473+
## Contributing
474+
475+
If you feel like something is missing or you want to add documentation, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Sitemaps in Headless WordPress"
33
description: "A guide on sitemaps in headless WordPress. It explains the challenges, and the different implementation approaches for sitemap generation."
44
---
55

6-
# Sitemaps in WordPress: A Comprehensive Overview
6+
## A Comprehensive Overview
77

88
## What is a Sitemap?
99
A sitemap is an XML file that provides a structured list of pages on a website by helping search engines discover and crawl content more efficiently. It acts as a roadmap of your website's structure, containing important metadata about each page.
@@ -108,7 +108,7 @@ This route will serve the WordPress `sitemap.xml` in your Next.js application dy
108108
- **Cons**
109109
* Limited flexibility for custom frontend routes not defined in WordPress
110110
* Requires proper URL transformation to replace backend URLs with frontend URLs
111-
* May require additional handling for caching and performance
111+
* May require additional handling for caching and performance
112112
* May propagate any errors experienced in WordPress when proxying the `sitemap.xml`
113113

114114
2. **Generating a Sitemap from GraphQL Content**
@@ -133,13 +133,13 @@ export async function generateSitemap() {
133133
fetchAllPages(),
134134
]);
135135
const allContent = [
136-
...data.posts.nodes.map(post => ({
137-
slug: `posts/${post.slug}`,
138-
modified: post.modified
136+
...data.posts.nodes.map(post => ({
137+
slug: `posts/${post.slug}`,
138+
modified: post.modified
139139
})),
140-
...data.pages.nodes.map(page => ({
141-
slug: page.slug,
142-
modified: page.modified
140+
...data.pages.nodes.map(page => ({
141+
slug: page.slug,
142+
modified: page.modified
143143
})),
144144
// Add custom frontend routes here
145145
{ slug: '', modified: new Date().toISOString() }, // Homepage
@@ -159,17 +159,17 @@ export async function generateSitemap() {
159159
}
160160
export async function getServerSideProps({ res }) {
161161
const sitemap = await generateSitemap();
162-
162+
163163
res.setHeader('Content-Type', 'application/xml');
164164
res.write(sitemap);
165165
res.end();
166-
166+
167167
return { props: {} };
168168
}
169169

170170
export async function GET() {
171171
const sitemap = await generateSitemap();
172-
172+
173173
return new Response(sitemap, {
174174
headers: {
175175
'Content-Type': 'application/xml',
@@ -182,7 +182,7 @@ export async function GET() {
182182
* Ability to include custom frontend routes not defined in WordPress
183183
* Easy integration with Next.js data fetching methods
184184

185-
- **Cons**:
185+
- **Cons**:
186186
* More complex implementation than proxying
187187
* Requires manual updates to include new content types or custom routes
188188
* May require pagination handling for large sites
@@ -199,25 +199,25 @@ import { DOMParser } from 'xmldom';
199199
export async function GET() {
200200
const response = await fetch(`${process.env.WORDPRESS_URL}/wp-sitemap.xml`);
201201
const sitemapIndex = await response.text();
202-
202+
203203
const parser = new DOMParser();
204204
const xmlDoc = parser.parseFromString(sitemapIndex, 'text/xml');
205205
const sitemapUrls = Array.from(xmlDoc.getElementsByTagName('loc')).map(
206206
node => node.textContent
207207
);
208-
208+
209209
const processedSitemaps = await Promise.all(
210210
sitemapUrls.map(async (url) => {
211211
const sitemapResponse = await fetch(url);
212212
const sitemapContent = await sitemapResponse.text();
213-
213+
214214
return sitemapContent.replace(
215215
new RegExp(process.env.WORDPRESS_URL, 'g'),
216216
process.env.FRONTEND_URL
217217
);
218218
})
219219
);
220-
220+
221221
const frontendRoutesSitemap = `
222222
<?xml version="1.0" encoding="UTF-8"?>
223223
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@@ -228,7 +228,7 @@ export async function GET() {
228228
<!-- Add more custom routes as needed -->
229229
</urlset>
230230
`;
231-
231+
232232
const combinedSitemap = `
233233
<?xml version="1.0" encoding="UTF-8"?>
234234
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@@ -242,7 +242,7 @@ export async function GET() {
242242
</sitemap>
243243
</sitemapindex>
244244
`;
245-
245+
246246
return new Response(combinedSitemap, {
247247
headers: {
248248
'Content-Type': 'application/xml',
@@ -261,3 +261,7 @@ export async function GET() {
261261
* Most complex implementation of the three approaches.
262262
* Requires handling multiple sitemap files
263263
* May have performance implications if not properly cached
264+
265+
## Contributing
266+
267+
If you feel like something is missing or you want to add documentation, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.

docs/how-to/install-toolkit-plugins/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Installing HWP Toolkit Plugins with Composer"
33
description: "A guide on how to install any HWP Toolkit plugin using Composer, which is the recommended way for modern WordPress development workflows."
44
---
55

6-
# Installing HWP Toolkit Plugins with Composer
6+
## Overview
77

88
You can install any HWP Toolkit plugin using Composer, which is the recommended way for modern WordPress development workflows.
99

@@ -15,6 +15,9 @@ You can also install them manually from our [Releases](https://github.com/wpengi
1515
- WordPress 6.0+
1616
- PHP 7.4+
1717

18+
>[!NOTE]
19+
> WPGraphQL Logging Plugin requires PHP 8.1.2 in order to work.
20+
1821
### Available Plugins
1922

2023
- [wpengine/hwp-previews](https://github.com/wpengine/hwptoolkit/tree/main/plugins/hwp-previews#readme)

0 commit comments

Comments
 (0)