-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bbdcb7d
Showing
169 changed files
with
28,619 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# vip-gutenberg-content-api | ||
|
||
Plugin to provide an API for customers to retrieve Gutenberg posts structured as JSON data. This is accomplished by parsing server-side block registry data and sourcing block attributes from HTML. | ||
|
||
## Assumptions & Limitations | ||
|
||
- All blocks must be [registered server-side](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#php-server-side). Client-side only blocks are not supported. | ||
- The plugin does not use any client-side editor code or modify existing posts. The content API should work statically with existing Gutenberg content. | ||
- (currently) The plugin has only been tested with current [documented block attributes](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/) and may not support markup or attributes created with early Gutenberg versions. We intend to expand testing to ensure early Gutenberg content parsing is possible. | ||
- (currently) `html`/rich text attributes are represented with inline HTML. We are researching non-HTML rich text serialization formats as an alternative. | ||
- (currently) The plugin provides a REST-only endpoint. WPGraphQL and typing may be supported in the future. | ||
|
||
## Examples | ||
|
||
### Live examples | ||
|
||
See [example WordPress post here](https://gutenberg-content-api-test.go-vip.net/hello-world/) and the associated content API output: [https://gutenberg-content-api-test.go-vip.net/wp-json/vip-content-api/v1/posts/1/blocks](https://gutenberg-content-api-test.go-vip.net/wp-json/vip-content-api/v1/posts/1/blocks). | ||
|
||
To view the block output for an arbitrary post ID, use this url: | ||
|
||
``` | ||
https://gutenberg-content-api-test.go-vip.net/wp-json/vip-content-api/v1/posts/<post_id>/blocks | ||
``` | ||
|
||
### Example content API output | ||
|
||
<table> | ||
<tr> | ||
<td>Example Post</td> | ||
<td>HTML Content</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<img src="https://github.com/wpcomvip/wordpress-vip-testing-gutenberg-content-api-test/raw/media/post-example.png?raw=true" alt="Example WordPress post with heading, quote, separator, and media-text blocks" /> | ||
</td> | ||
<td> | ||
|
||
```html | ||
<!-- wp:heading --> | ||
<h2>Heading 1</h2> | ||
<!-- /wp:heading --> | ||
|
||
<!-- wp:quote --> | ||
<blockquote class="wp-block-quote"> | ||
<!-- wp:paragraph --> | ||
<p>Text in quote</p> | ||
<!-- /wp:paragraph --> | ||
<cite>~ Citation, 2023</cite> | ||
</blockquote> | ||
<!-- /wp:quote --> | ||
|
||
<!-- wp:separator --> | ||
<hr class="wp-block-separator has-alpha-channel-opacity"/> | ||
<!-- /wp:separator --> | ||
|
||
<!-- wp:media-text {"mediaId":6,"mediaLink":"https://gutenberg-content-api-test.go-vip.net/?attachment_id=6","mediaType":"image"} --> | ||
<div class="wp-block-media-text alignwide is-stacked-on-mobile"> | ||
<figure class="wp-block-media-text__media"> | ||
<img src="https://gutenberg-content-api-test.go-vip.net/wp-content/uploads/2023/01/4365xAanG8.jpg?w=1024" alt="" class="wp-image-6 size-full"/> | ||
</figure> | ||
|
||
<div class="wp-block-media-text__content"> | ||
<!-- wp:paragraph {"placeholder":"Content…"} --> | ||
<p>Content on right side of media-text.</p> | ||
<!-- /wp:paragraph --> | ||
</div> | ||
</div> | ||
<!-- /wp:media-text --> | ||
``` | ||
|
||
</td> | ||
</tr> | ||
</table> | ||
|
||
--- | ||
|
||
Content API result: | ||
|
||
```json | ||
{ | ||
"blocks": [ | ||
{ | ||
"name": "core/heading", | ||
"attributes": { | ||
"content": "Heading 1", | ||
"level": 2 | ||
} | ||
}, | ||
{ | ||
"name": "core/quote", | ||
"attributes": { | ||
"value": "", | ||
"citation": "~ Citation, 2023" | ||
}, | ||
"innerBlocks": [ | ||
{ | ||
"name": "core/paragraph", | ||
"attributes": { | ||
"content": "Text in quote", | ||
"dropCap": false | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "core/separator", | ||
"attributes": { | ||
"opacity": "alpha-channel" | ||
} | ||
}, | ||
{ | ||
"name": "core/media-text", | ||
"attributes": { | ||
"mediaId": 6, | ||
"mediaLink": "https:/gutenberg-content-api-test.go-vip.net/?attachment_id=6", | ||
"mediaType": "image", | ||
"align": "wide", | ||
"mediaAlt": "", | ||
"mediaPosition": "left", | ||
"mediaUrl": "https:/gutenberg-content-api-test.go-vip.net/wp-content/uploads/2023/01/4365xAanG8.jpg?w=1024", | ||
"mediaWidth": 50, | ||
"isStackedOnMobile": true | ||
}, | ||
"innerBlocks": [ | ||
{ | ||
"name": "core/paragraph", | ||
"attributes": { | ||
"placeholder": "Content\u2026", | ||
"content": "Content on right side of media-text.", | ||
"dropCap": false | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"scripts": { | ||
"phpcs": "phpcs", | ||
"phpcs-fix": "phpcbf", | ||
"test": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/vip-gutenberg-content-api/phpunit.xml.dist'", | ||
"test-multisite": "wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/vip-gutenberg-content-api/phpunit.xml.dist'", | ||
"test-debug": "wp-env run tests-wordpress '/var/www/html/wp-content/plugins/vip-gutenberg-content-api/vendor/bin/phpunit -c /var/www/html/wp-content/plugins/vip-gutenberg-content-api/phpunit.xml.dist'", | ||
"test-watch": [ | ||
"Composer\\Config::disableProcessTimeout", | ||
"nodemon -w ./ --ignore vendor/ -e php --exec 'composer run test'" | ||
] | ||
}, | ||
"require": { | ||
"masterminds/html5": "^2.7", | ||
"symfony/dom-crawler": "^5.4", | ||
"symfony/css-selector": "^5.4" | ||
}, | ||
"require-dev": { | ||
"php": ">=7.4", | ||
"phpunit/phpunit": "^9.5", | ||
"wp-phpunit/wp-phpunit": "^6.1", | ||
"dealerdirect/phpcodesniffer-composer-installer": "^1.0", | ||
"phpcompatibility/phpcompatibility-wp": "^2.1", | ||
"wp-coding-standards/wpcs": "^2.3", | ||
"automattic/vipwpcs": "^2.2", | ||
"yoast/phpunit-polyfills": "^1.0", | ||
"dms/phpunit-arraysubset-asserts": "^0.4.0" | ||
}, | ||
"config": { | ||
"platform": { | ||
"php": "7.4" | ||
}, | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true | ||
} | ||
} | ||
} |
Oops, something went wrong.