Repository navigation
Documentation: Move the theme into Meta so wporg-documentation-2022 can be retired #950
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
Open
obenland
wants to merge
11
commits into
WordPress:trunk
Choose a base branch
from
obenland:add/documentation-2022-theme
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fb33b09
Documentation: Import the theme from WordPress/wporg-documentation-20…
obenland 5409bd7
Documentation: Bring the theme in line with the Meta coding standards
obenland 3efc6dd
Documentation: Build the theme with @wordpress/scripts 36 and commit …
obenland 3b9b80f
Documentation: Move the site's redirects into the theme
obenland edeb8e8
Environments: Add a Documentation environment
obenland 9d43468
Documentation: Lint the theme's JS and CSS, and check its build is fresh
obenland c473460
Documentation: Lint the theme through the shared JS/CSS workflow
obenland 4c0ffe5
Documentation: Close the comment form group's block attributes
obenland 7f0d74a
Documentation: Fix the header's block attributes and the feedback for…
obenland 23c17d8
Documentation: Leave the term description block alone without a match…
obenland 819236e
Environments: Say that the Documentation refresh only adds missing co…
obenland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,30 @@ | ||
| { | ||
| "core": "WordPress/WordPress#master", | ||
| "phpVersion": "8.4", | ||
| "testsEnvironment": false, | ||
| "plugins": [ | ||
| "https://downloads.wordpress.org/plugin/gutenberg.zip", | ||
| "https://downloads.wordpress.org/plugin/jetpack.zip", | ||
| "https://downloads.wordpress.org/plugin/syntaxhighlighter.zip", | ||
| "../wordpress.org/public_html/wp-content/plugins/support-helphub" | ||
| ], | ||
| "themes": [ | ||
| "../wordpress.org/public_html/wp-content/themes/pub/wporg-documentation-2022", | ||
| "WordPress/wporg-parent-2021#build" | ||
| ], | ||
| "mappings": { | ||
| "wp-content/mu-plugins": "./mocks/mu-plugins", | ||
| "wp-content/mu-plugins/pub": "../wordpress.org/public_html/wp-content/mu-plugins/pub", | ||
| "wp-content/mu-plugins/wporg-mu-plugins": "WordPress/wporg-mu-plugins#build", | ||
| "wp-content/env-bin": "./documentation/bin" | ||
| }, | ||
| "lifecycleScripts": { | ||
| "afterStart": "bash documentation/bin/after-start.sh" | ||
| }, | ||
| "config": { | ||
| "WP_DEBUG": true, | ||
| "JETPACK_DEV_DEBUG": true, | ||
| "WP_ENVIRONMENT_TYPE": "local", | ||
| "GLOTPRESS_LOCALES_PATH": "/var/www/html/wp-content/mu-plugins/pub/locales/locales.php" | ||
| } | ||
| } |
This file contains hidden or 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,27 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Runs after wp-env start. Activates the theme, sets up permalinks, and imports | ||
| # the Documentation content from WordPress.org. | ||
| # | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| CONFIG="--config documentation/.wp-env.json" | ||
| WP="npx wp-env $CONFIG run cli --" | ||
|
|
||
| echo "Activating theme..." | ||
| $WP wp theme activate wporg-documentation-2022 | ||
|
|
||
| $WP wp option update blogname "Documentation" | ||
| $WP wp option update blogdescription "We’ve got a variety of resources to help you get the most out of WordPress." | ||
|
|
||
| # Reapplied on every start because wp-env resets the structure whenever it | ||
| # reconfigures WordPress. | ||
| echo "Setting up permalinks..." | ||
| $WP wp rewrite structure '/%postname%/' --hard | ||
|
|
||
| # Idempotent — the import gates itself on the wporg_docs_env_imported option, | ||
| # which `npm run documentation:refresh` clears. | ||
| $WP wp eval-file wp-content/env-bin/import-content.php --user=admin | ||
|
|
||
| echo "Documentation environment ready!" |
This file contains hidden or 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,229 @@ | ||
| <?php | ||
| /** | ||
| * Import Documentation content from WordPress.org for local development. | ||
| * | ||
| * Copies the categories, pages, articles, and WordPress version pages from the | ||
| * live site's REST API. Posts keep their production IDs, so links between them | ||
| * and the IDs in production URLs line up locally. | ||
| * | ||
| * The REST API only exposes rendered content to logged-out requests, so posts | ||
| * are imported as rendered HTML rather than block markup. | ||
| * | ||
| * Usage: | ||
| * wp eval-file wp-content/env-bin/import-content.php --user=admin | ||
| * | ||
| * No strict_types declaration: eval-file evaluates the file inline, where a | ||
| * declare() cannot be the first statement. | ||
| * | ||
| * @package wporg-env | ||
| */ | ||
|
|
||
| namespace WordPressdotorg\Documentation\Env; | ||
|
|
||
| use RuntimeException; | ||
| use WP_CLI; | ||
|
|
||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| exit; | ||
| } | ||
|
|
||
| const API_BASE = 'https://wordpress.org/documentation/wp-json/wp/v2/'; | ||
|
|
||
| /** | ||
| * Fetches every item from a REST collection, following pagination. | ||
| * | ||
| * @param string $endpoint Collection route, relative to the wp/v2 namespace. | ||
| * @return array[] Decoded items, in API order. | ||
| * | ||
| * @throws RuntimeException When a page of the collection cannot be fetched. | ||
| */ | ||
| function fetch_all( string $endpoint ): array { | ||
| $items = array(); | ||
| $page = 1; | ||
| $total_pages = 1; | ||
|
|
||
| do { | ||
| $url = add_query_arg( | ||
| array( | ||
| 'per_page' => 100, | ||
| 'page' => $page, | ||
| ), | ||
| API_BASE . $endpoint | ||
| ); | ||
| $response = wp_remote_get( $url, array( 'timeout' => 60 ) ); | ||
|
|
||
| $batch = is_wp_error( $response ) ? null : json_decode( wp_remote_retrieve_body( $response ), true ); | ||
| if ( 200 !== wp_remote_retrieve_response_code( $response ) || ! is_array( $batch ) ) { | ||
| throw new RuntimeException( esc_html( "Could not fetch {$endpoint} (page {$page}) from wordpress.org." ) ); | ||
| } | ||
|
|
||
| $items = array_merge( $items, $batch ); | ||
| $total_pages = (int) wp_remote_retrieve_header( $response, 'x-wp-totalpages' ); | ||
| ++$page; | ||
| } while ( $page <= $total_pages ); | ||
|
|
||
| return $items; | ||
| } | ||
|
|
||
| /** | ||
| * Imports the terms of a taxonomy, parents before their children. | ||
| * | ||
| * @param string $endpoint Terms route, relative to the wp/v2 namespace. | ||
| * @param string $taxonomy Local taxonomy name. | ||
| * @return int[] Local term IDs, keyed by production term ID. | ||
| */ | ||
| function import_terms( string $endpoint, string $taxonomy ): array { | ||
| $terms = fetch_all( $endpoint ); | ||
| $map = array(); | ||
|
|
||
| while ( $terms ) { | ||
| $deferred = array(); | ||
|
|
||
| foreach ( $terms as $term ) { | ||
| $parent = (int) ( $term['parent'] ?? 0 ); | ||
| if ( $parent && ! isset( $map[ $parent ] ) ) { | ||
| $deferred[] = $term; | ||
| continue; | ||
| } | ||
|
|
||
| $existing = get_term_by( 'slug', $term['slug'], $taxonomy ); | ||
| if ( $existing ) { | ||
| $map[ (int) $term['id'] ] = (int) $existing->term_id; | ||
| continue; | ||
| } | ||
|
|
||
| $result = wp_insert_term( | ||
| wp_specialchars_decode( $term['name'], ENT_QUOTES ), | ||
| $taxonomy, | ||
| array( | ||
| 'slug' => $term['slug'], | ||
| 'description' => $term['description'] ?? '', | ||
| 'parent' => $parent ? $map[ $parent ] : 0, | ||
| ) | ||
| ); | ||
|
|
||
| if ( is_wp_error( $result ) ) { | ||
| WP_CLI::warning( "Could not create {$taxonomy} '{$term['slug']}': " . $result->get_error_message() ); | ||
|
|
||
| // Its children still import, at the top level. | ||
| $map[ (int) $term['id'] ] = 0; | ||
| continue; | ||
| } | ||
|
|
||
| $map[ (int) $term['id'] ] = (int) $result['term_id']; | ||
| } | ||
|
|
||
| // Whatever is left has a parent the API did not return. | ||
| if ( count( $deferred ) === count( $terms ) ) { | ||
| WP_CLI::warning( count( $deferred ) . " {$taxonomy} terms skipped: their parents are missing." ); | ||
| break; | ||
| } | ||
|
|
||
| $terms = $deferred; | ||
| } | ||
|
|
||
| WP_CLI::log( sprintf( 'Imported %d %s terms.', count( array_filter( $map ) ), $taxonomy ) ); | ||
|
|
||
| return $map; | ||
| } | ||
|
|
||
| /** | ||
| * Imports the posts of a post type, keeping their production IDs. | ||
| * | ||
| * @param string $endpoint Posts route, relative to the wp/v2 namespace. | ||
| * @param string $post_type Local post type name. | ||
| * @param array[] $taxonomies Term ID maps from import_terms(), keyed by the | ||
| * REST field that holds the post's term IDs, e.g. | ||
| * `array( 'category' => array( 'taxonomy' => 'category', 'map' => $map ) )`. | ||
| * @return void | ||
| */ | ||
| function import_posts( string $endpoint, string $post_type, array $taxonomies = array() ): void { | ||
| $imported = 0; | ||
|
|
||
| foreach ( fetch_all( $endpoint ) as $item ) { | ||
| if ( get_post( (int) $item['id'] ) ) { | ||
| continue; | ||
| } | ||
|
|
||
| $post_id = wp_insert_post( | ||
| array( | ||
| 'import_id' => (int) $item['id'], | ||
| 'post_type' => $post_type, | ||
| 'post_status' => 'publish', | ||
| 'post_title' => html_entity_decode( $item['title']['rendered'], ENT_QUOTES, 'UTF-8' ), | ||
| 'post_name' => $item['slug'], | ||
| 'post_content' => $item['content']['rendered'], | ||
| 'post_excerpt' => wp_strip_all_tags( $item['excerpt']['rendered'] ?? '' ), | ||
| 'post_date' => $item['date'], | ||
| 'post_date_gmt' => $item['date_gmt'], | ||
| 'post_parent' => (int) ( $item['parent'] ?? 0 ), | ||
| 'menu_order' => (int) ( $item['menu_order'] ?? 0 ), | ||
| ), | ||
| true | ||
| ); | ||
|
|
||
| if ( is_wp_error( $post_id ) ) { | ||
| WP_CLI::warning( "Could not create {$post_type} '{$item['slug']}': " . $post_id->get_error_message() ); | ||
| continue; | ||
| } | ||
|
|
||
| foreach ( $taxonomies as $field => $taxonomy ) { | ||
| $term_ids = array_filter( | ||
| array_map( | ||
| static fn ( $id ): int => $taxonomy['map'][ (int) $id ] ?? 0, | ||
| (array) ( $item[ $field ] ?? array() ) | ||
| ) | ||
| ); | ||
|
|
||
| if ( $term_ids ) { | ||
| wp_set_object_terms( $post_id, array_values( $term_ids ), $taxonomy['taxonomy'] ); | ||
| } | ||
| } | ||
|
|
||
| ++$imported; | ||
| } | ||
|
|
||
| WP_CLI::log( "Imported {$imported} {$post_type} posts." ); | ||
| } | ||
|
|
||
| if ( get_option( 'wporg_docs_env_imported' ) ) { | ||
| WP_CLI::log( 'Already imported, skipping.' ); | ||
| return; | ||
| } | ||
|
|
||
| WP_CLI::log( 'Importing Documentation content from WordPress.org...' ); | ||
|
|
||
| /* | ||
| * Only mark the import done once everything arrived. Every step skips what | ||
| * already exists, so an interrupted import resumes on the next start. | ||
| */ | ||
| try { | ||
| $categories = import_terms( 'category', 'category' ); | ||
| $releases = import_terms( 'helphub_major_release', 'helphub_major_release' ); | ||
|
|
||
| import_posts( 'pages', 'page' ); | ||
| import_posts( | ||
| 'articles', | ||
| 'helphub_article', | ||
| array( | ||
| 'category' => array( | ||
| 'taxonomy' => 'category', | ||
| 'map' => $categories, | ||
| ), | ||
| ) | ||
| ); | ||
| import_posts( | ||
| 'wordpress-versions', | ||
| 'helphub_version', | ||
| array( | ||
| 'helphub_major_release' => array( | ||
| 'taxonomy' => 'helphub_major_release', | ||
| 'map' => $releases, | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| update_option( 'wporg_docs_env_imported', time() ); | ||
| } catch ( RuntimeException $e ) { | ||
| WP_CLI::warning( $e->getMessage() . ' The import resumes on the next start.' ); | ||
| } | ||
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
wordpress.org/public_html/wp-content/themes/pub/wporg-documentation-2022/.nvmrc
This file contains hidden or 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 @@ | ||
| 24 |
21 changes: 21 additions & 0 deletions
21
.../public_html/wp-content/themes/pub/wporg-documentation-2022/build/article-list/block.json
This file contains hidden or 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,21 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/block.json", | ||
| "apiVersion": 2, | ||
| "name": "wporg/article-list", | ||
| "version": "0.1.0", | ||
| "title": "Article list", | ||
| "category": "design", | ||
| "icon": "", | ||
| "description": "Article list for a top-level category.", | ||
| "textdomain": "wporg", | ||
| "supports": { | ||
| "html": false | ||
| }, | ||
| "attributes": { | ||
| "category": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "editorScript": "file:./index.js", | ||
| "style": "file:./style-index.css" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.