Skip to content

Commit 3f382a3

Browse files
authored
docs: transfer new docs (#2046)
* transfer new docs * chore: update docs * refactor: change to md and frontmatter * fix: docs page to frontmatter * fix: more mssied metadata to frontmatter * fix: remove tabs from yaml frontmatter * fix: incorect tab changes * fix: incorrect newline * fix: another wrong indent * docs: document new documentation
1 parent d389f91 commit 3f382a3

File tree

86 files changed

+5073
-1
lines changed

Some content is hidden

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

86 files changed

+5073
-1
lines changed

README.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,39 @@ Faust.js is a toolkit for building Next.js applications for headless WordPress s
2727

2828
## Documentation
2929

30-
Visit [https://faustjs.org/docs/getting-started](https://faustjs.org/docs/getting-started) to view the full documentation.
30+
Visit [https://faustjs.org/docs/](https://faustjs.org/docs/getting-started) to view the full documentation.
31+
32+
### Editing Docs
33+
34+
Docs are MD in [`docs`](docs/). Here are a couple things you should know!
35+
36+
1. Our Docs support [Github Flavored Markdown](https://github.github.com/gfm/) (GFM).
37+
2. Images should be stored along side the doc that uses them in an `images/` folder.
38+
3. Shared Images can be stored in a shared folder @ `docs/images`
39+
4. [Callouts](https://github.com/lin-stephanie/rehype-callouts?tab=readme-ov-file#rehype-callouts): These are similar to block quotes or an aside but for various warnings, info, pro times, etc.
40+
5. Code Blocks:
41+
42+
- Required
43+
1. Specify a language: ` ```js ` or `` `const inlineCode = [1,2,3];{:js}` ``
44+
- Commands for a users terminal = `bash`
45+
- env files = `ini`
46+
- JavaScript = `js`
47+
- TypeScript = `ts`
48+
- GraphQL = `gql`
49+
- JSON = `json`
50+
- For a full list see: https://shiki.style/languages
51+
2. Add [line numbers](https://rehype-pretty.pages.dev/#line-numbers) to any complex code. `ini` and `bash` don't need to show line numbers generally. ` ```js showLineNumbers`
52+
3. Complete files should have a [file names](https://rehype-pretty.pages.dev/#titles) ` ```js title="pages/_app.js`
53+
- Optional
54+
55+
1. Lines can be [highlighted](https://rehype-pretty.pages.dev/#highlight-lines) in code blocks ` ```js {1,3-5}`. There are a variety of advanced highlighting methods, see: https://rehype-pretty.pages.dev/#highlight-lines
56+
2. Lines may be [diffed](https://shiki.style/packages/transformers#transformernotationdiff) in a code block:
57+
58+
```js
59+
console.log('hewwo') // [!code --]
60+
console.log('hello') // [!code ++]
61+
console.log('goodbye')
62+
```
3163

3264
## WordPress Plugin (FaustWP)
3365

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: "Apollo Client Basics"
3+
description: "Learn about core Apollo Client concepts like queries, fragments, mutations, and caching as they relate to Faust.js and WordPress."
4+
---
5+
6+
Faust.js uses `@apollo/client` under the hood to perform GraphQL operations against your WordPress backend. Having a solid understanding of Apollo Client queries, fragments, and mutations will help you get the most out of Faust.js.
7+
8+
## Apollo Client GraphQL Concepts
9+
10+
Below are core concepts for Apollo and GraphQL with links to the docs for your reference.
11+
12+
- [Queries](https://www.apollographql.com/docs/react/data/queries) – Retrieve data from your WordPress site.
13+
- [Fragments](https://www.apollographql.com/docs/react/data/fragments) – Modularize your queries to make them more maintainable.
14+
- [Mutations](https://www.apollographql.com/docs/graphos/get-started/concepts/graphql#mutations) – Update data in your WordPress backend.
15+
- [Apollo Client Cache](https://www.apollographql.com/docs/react/caching/cache-configuration) – Cache responses to minimize network usage.
16+
17+
## Faust.js-Specific Notes
18+
19+
- You don’t need to create or configure the client object yourself; Faust handles that for you.
20+
- You can still customize the underlying Apollo Client via plugin filters if you need advanced configuration.

docs/explanation/blocks-faq/index.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "Blocks FAQ"
3+
description: "Frequently asked questions about Blocks."
4+
---
5+
6+
## _"What if the block is missing some attributes?"_
7+
8+
If the block does not have any attributes or has only a few of them declared in the `block.json` for that block (you can view the `block.json` file for the block at https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/), you can still try to extend the block API by declaring additional attributes for that block.
9+
10+
Follow the [filters reference guide](/docs/reference/use-blocks-theme/) to create a block that uses the `additional_block_attributes` property. The attributes will then be available to query from that block.
11+
12+
```php
13+
class CoreCode extends WPGraphQL\ContentBlocks\Blocks\Block
14+
{
15+
protected ?array $additional_block_attributes = array(
16+
// Write your attributes here
17+
);
18+
}
19+
```
20+
21+
> [!NOTE]
22+
> If you include those extensions in a custom plugin, your Headless Website application is dependent on the inclusion of this plugin. You need to make sure you bundle them together; otherwise, the queries you perform in the application will fail.
23+
24+
## _"Can I style the block differently?"_"
25+
26+
Yes, you can style the block in many ways, choosing to ignore some of the attributes altogether. You can also use an external React Library to style the block, such as Material UI or ChakraUI.
27+
28+
Bear in mind that this will almost always result in a degraded user editing experience, as the styles in the WordPress block editor view won't match the styles of the rendered headless page.
29+
30+
## _"What if the block contains custom JavaScript assets?"_
31+
32+
Some Core blocks include JavaScript assets that are injected into the WordPress page so they can run in the front view. Many [dynamic blocks](https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/creating-dynamic-blocks/) use this functionality to include user interactivity. Since React is not bundled as a dependency in the browser, the client-side code that WordPress ships to the frontend in traditional WordPress sites typically consists of plain JavaScript or jQuery.
33+
34+
To review and handle bundled JavaScript assets, consider these options:
35+
36+
- **Include them in your code**: This is not recommended, as React does not play well with plain JavaScript and jQuery, which may lead to compatibility issues.
37+
- **Rewrite them as React components**: You can attempt to rewrite the code in React. If the bundled code can be understood and rewritten with low effort, then this could be a viable approach.
38+
- **Use an equivalent React Component from a library**: A simpler alternative is to find a compatible React package and use it instead of replicating the block's interactivity. This can often free the developer from implementing the functionality from scratch.
39+
40+
Inevitably, this is a common challenge when using Blocks in a Headless Website setup, so it's up to you to weigh the pros and cons of each approach.
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: "Deploying Your App"
3+
description: "Explains the various options for deploying your Faust.js App to production."
4+
---
5+
6+
The following explains the various options for deploying your Faust.js App to production.
7+
8+
## Picking The Right Node.js Version
9+
10+
Faust.js supports supported versions of Node.js v16.0.0 or newer. The [latest LTS version](https://nodejs.org/en/about/previous-releases) of Node.js is recommended and anything [compatible with your Next.js](https://nextjs.org/docs/pages/getting-started/installation) version. Please make sure you are using a Node.js version that is compatible when deploying to avoid unexpected errors.
11+
12+
Faust.js uses the `package.json` [engines field](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#engines) that will produce warnings when your package is installed as a dependency under a non compatible NPM/Node version.
13+
14+
## Building Your App
15+
16+
Since Faust.js is built on top of Next.js, it shares the same build process. For details on how Next.js generates optimized production builds, refer to the [Next.js Build API](https://nextjs.org/docs/pages/building-your-application/deploying#nextjs-build-api) documentation. Additionally, you can explore the Headless Platform [framework guide](https://developers.wpengine.com/docs/atlas/framework-guides/next-js/next/) for Next.js apps.
17+
18+
## Deploying to WP Engine's Headless Platform
19+
20+
The Headless Platform is the most effortless way to deploy a Faust.js app. Connect your GitHub repo and Headless Platform will automatically build and deploy your Faust.js project on each push. Some of the benefits you get out of the box are:
21+
22+
- Automatic installation of required WordPress plugins (Faust, WPGraphQL, etc.)
23+
- Automatic setup of Faust.js environment variables
24+
- Automatic configuration of the Faust WordPress plugin’s settings
25+
- WordPress and your headless app live in the same place
26+
- Automatic rebuilds on code changes
27+
- Support for [custom domains](https://wpengine.com/support/add-domain-in-user-portal/)
28+
29+
Deploy your Faust.js app and try for the [Headless Platform](https://wpengine.com/headless-wordpress/#form) for free!
30+
31+
For further reference, please check out the Headless Platform [framework guide](https://developers.wpengine.com/docs/atlas/framework-guides/next-js/next/) docs on Deploying Next.js.
32+
33+
> [!NOTE]
34+
> If deploying from the WP Engine portal using your own repository (without beginning with a blueprint), you will need to set your environment variables manually. Learn how by taking a look at our [platform docs](https://developers.wpengine.com/docs/atlas/getting-started/deploy-from-existing-repo/#set-environment-variables-optional).
35+
36+
## Self Hosted
37+
38+
You can also self host Faust.js apps on any hosting provider that supports Node.js.
39+
40+
To self host your Faust.js app, you will need to first build the app, then start it. Make sure you have the `faust build` and `faust start` scripts specified in your `package.json` file:
41+
42+
```json title="package.json"
43+
{
44+
"scripts": {
45+
"build": "faust build",
46+
"start": "faust start"
47+
}
48+
}
49+
```
50+
51+
Then, from the Node.js server run `npm run build` to build the app and `npm run start` to start it.
52+
For reference, please visit the [Next.js self-hosted deployment](https://nextjs.org/docs/pages/building-your-application/deploying#self-hosting) docs.

docs/explanation/index.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: "Explanation"
3+
description: "High-level conceptual guides that provide background information and understanding of Headless WordPress development."
4+
---
5+
6+
I see you found the root of the Explanatory guides! Explanatory guides are a place where we step away from code and talk high-level concepts and import background information. If you are looking to grow your understanding of Headless WordPress, you are in the right place.
7+
8+
> [!note] Learn More
9+
> For more info on how we layout our documentation and the the role played by Explanatory Guides, please read about the [_Diátaxis_](https://diataxis.fr/explanation/) approach we use.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: "Migrate From WPGraphQL Gutenberg"
3+
description: "Migrate from wp-graphql-gutenberg to wp-graphql-content-blocks. This guide covers differences between the two plugins, reasons for migration, and step-by-step instructions for updating your GraphQL queries and block structures to ensure compatibility with Faust.js and modern WPGraphQL best practices."
4+
---
5+
6+
With [`wp-graphql-gutenberg`](https://github.com/pristas-peter/wp-graphql-gutenberg) being sunset you may find yourself needing to move to the improved [`wp-graphql-content-blocks`](https://github.com/wpengine/wp-graphql-content-blocks) plugin.
7+
8+
## What's the difference?
9+
10+
Both plugins extend WPGraphQL to add support for blocks (aka. Gutenberg) to the WPGraphQL schema.
11+
12+
However, there are some key differences that you should be aware of:
13+
14+
- WPGraphQL Gutenberg gets the blocks registry and sends it in a network request to the WordPress PHP application. So it needs to be synced from time to time.
15+
16+
- It also allows the blocks to be served as JSON using the `blocksJSON` field. If requesting data this way, the data is not typechecked and you may overfetch data as a side effect.
17+
18+
- Block attributes are using their own types, containing different type for deprecated versions. For example:
19+
20+
```gql
21+
...on CoreParagraphBlock {
22+
attributes {
23+
...on CoreParagraphBlockAttributes {
24+
content
25+
}
26+
...on CoreParagraphBlockDeprecatedV1Attributes {
27+
content
28+
}
29+
}
30+
}
31+
```
32+
33+
- It does not allow blocks to be returned as a flat list so you have to use deeply nested queries to get the list of innerBlocks (and this won’t nearly solve the issue 100%).
34+
35+
- wp-graphql-content-blocks does not save anything in the database (this is actually a good thing) compared to wp-graphql-gutenberg. Therefore it only supports previews when the **“preview”** button is hit in the editor.
36+
37+
## How do I migrate a block from wp-graphql-gutenberg?
38+
39+
To answer this question you will have check how you queried the blocks using `wp-graphql-gutenberg`. There are two different cases that you have to consider here:
40+
41+
### You used the `blocksJSON` property to get the blocks data
42+
43+
The `wp-graphql-content-blocks` plugin does not expose the `blocksJSON` fields, because it is problematic to do so. Getting the data as plain JSON directly from the database completely overrides the principles of GraphQL and ignores the type safety of the system. If one of the properties is altered, you have no guarantee that the GraphQL server will catch them. Plus, most of the times you will over fetch data leading to slower queries, especially if you have lots of content on the screen.
44+
45+
So, due to the lack of Introspection, unpredictability, and in order to promote best practices, `wp-graphql-content-blocks` do not expose the block data as plain JSON. Instead, it is recommended to use GraphQL types to retrieve associated block attributes and fields.The effort required to add block fragments is not high. If you follow the recommended approach of co-located fragments, you may add them as properties to each of your block expected attribute list and make sure that you include those into the page query string.
46+
47+
Take a look at the following example taken from [WebDevStudios nextjs-wordpress-starter](https://github.com/WebDevStudios/nextjs-wordpress-starter/blob/main/components/blocks/core/BlockCode/BlockCode.js). It shows an implementation of the `CoreCode` block using `wp-graphql-gutenberg` and getting the data using `blockJSON`.
48+
49+
With it, you would have to create a fragment like this:
50+
51+
```gql
52+
CoreCode.fragments = {
53+
key: `CoreCodeBlockFragment`,
54+
entry: gql`
55+
fragment CoreCodeBlockFragment on CoreCodeBlock {
56+
attributes {
57+
...on CoreCodeBlockAttributes {
58+
anchor
59+
backgroundColor
60+
content
61+
className
62+
gradient
63+
style
64+
textColor
65+
}
66+
}
67+
}
68+
`,
69+
};
70+
```
71+
72+
Based on the [creating a custom block](/docs/how-to/custom-blocks/) guide from the WordPress Core Blocks you just need to add the following fragment as a new property:
73+
74+
```gql CoreCode.fragments = {
75+
key: `CoreCodeBlockFragment`,
76+
entry: gql`
77+
fragment CoreCodeBlockFragment on CoreCode {
78+
attributes {
79+
anchor
80+
backgroundColor
81+
content
82+
className
83+
gradient
84+
style
85+
textColor
86+
}
87+
}
88+
`,
89+
};
90+
```
91+
92+
When the `WordPressBlocksViewer` renders the component, it passes the whole block data as a property of that block. If your block is designed to accept different properties for attributes and for `innerBlocks` you have to create a wrapper to forward the properties into the right slots:
93+
94+
```js title="CoreCode.js"
95+
export default function CoreCode({attributes, children}) {
96+
const BlockCode = dynamic(() => import('@/components/blocks/core/BlockCode'))
97+
return <BlockCode {...attributes} innerBlocks={children}>
98+
}
99+
```
100+
101+
### You used the block field with GraphQL types and fragments
102+
103+
If you were using the block field from the `wp-graphql-gutenberg` then most of the component fragment queries should be the same with the following exceptions.
104+
105+
You should be querying the block attributes without qualifying their type:
106+
107+
**Before:**
108+
109+
```gql
110+
...on CoreParagraphBlock {
111+
attributes {
112+
...on CoreParagraphBlockAttributes {
113+
content
114+
}
115+
}
116+
}
117+
```
118+
119+
**After:**
120+
121+
```gql
122+
...on CoreParagraphBlock {
123+
attributes {
124+
content
125+
}
126+
}
127+
```
128+
129+
There are no separate fields `previewBlocks` and `previewBlocksJSON`. If you want to preview posts or pages you should be setting the `asPreview` boolean to `true` for the post/page in your GraphQL request (this is how Faust.js previews work under the hood).
130+
131+
The base interface for each block contains different fields, so you need to make sure your queries use the valid ones from this list:
132+
133+
- `renderedHTML`: It’s the HTML of the block as rendered by the render_block function.
134+
135+
- `name`: The actual name of the block taken from its block.json spec.
136+
137+
- `__typename`: The type of block transformed from the name field in camel-case notation.
138+
139+
- `apiVersion`: The apiVersion of the block taken from its block.json spec.
140+
141+
- `innerBlocks`: The `innerblock` list of that block.
142+
143+
-`isDynamic`: Whether the block is dynamic or not, taken from its block.json spec.
144+
145+
- `clientId`, `parentClientId`: Unique identifiers for the block and the parent of the block.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "Migrating to TypeScript"
3+
description: "Guide for migrating existing Next.js pages to TypeScript in a Faust.js project with resources and references."
4+
---
5+
6+
If you have existing Next.js pages that you want to migrate to TypeScript, you can follow the [official TypeScript Docs](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html) for general TypeScript migration tips.
7+
8+
For Faust, see the [TypeScript Reference Doc](/docs/reference/typescript).
9+
10+
## Further Reading
11+
12+
- [TypeScript Reference](/docs/reference/typescript)
13+
- [Typing GraphQL Queries with GraphQL Codegen](/docs/how-to/generate-types-with-graphql-codegen)
Loading
Loading

0 commit comments

Comments
 (0)