-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix accessibility of GitHub links (#388)
* Add context to handbook github links for screen readers Move handbook article meta github to a block so that we can get the title * Patch after rebase * DRY block markup
- Loading branch information
1 parent
0479205
commit 0b861ea
Showing
7 changed files
with
143 additions
and
98 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
56 changes: 0 additions & 56 deletions
56
source/wp-content/themes/wporg-developer-2023/patterns/article-meta-github.php
This file was deleted.
Oops, something went wrong.
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
17 changes: 17 additions & 0 deletions
17
source/wp-content/themes/wporg-developer-2023/src/article-meta-github/block.json
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,17 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "wporg/article-meta-github", | ||
"version": "0.1.0", | ||
"title": "Article Meta GitHub", | ||
"category": "widgets", | ||
"icon": "smiley", | ||
"description": "", | ||
"usesContext": [ "postId", "postType" ], | ||
"attributes": {}, | ||
"supports": { | ||
"inserter": false | ||
}, | ||
"textdomain": "wporg", | ||
"editorScript": "file:./index.js" | ||
} |
104 changes: 104 additions & 0 deletions
104
source/wp-content/themes/wporg-developer-2023/src/article-meta-github/block.php
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,104 @@ | ||
<?php | ||
namespace WordPressdotorg\Theme\Developer_2023\Article_Meta_Github; | ||
|
||
add_action( 'init', __NAMESPACE__ . '\init' ); | ||
|
||
/** | ||
* Registers the block using the metadata loaded from the `block.json` file. | ||
* Behind the scenes, it registers also all assets so they can be enqueued | ||
* through the block editor in the corresponding context. | ||
* | ||
* @see https://developer.wordpress.org/reference/functions/register_block_type/ | ||
*/ | ||
function init() { | ||
register_block_type( | ||
dirname( dirname( __DIR__ ) ) . '/build/article-meta-github', | ||
array( | ||
'render_callback' => __NAMESPACE__ . '\render', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Render the block content. | ||
* | ||
* @param array $attributes Block attributes. | ||
* @param string $content Block default content. | ||
* @param WP_Block $block Block instance. | ||
* | ||
* @return string Returns the block markup. | ||
*/ | ||
function render( $attributes, $content, $block ) { | ||
$github_handbooks = array( | ||
'wpcs-handbook', | ||
'blocks-handbook', | ||
'rest-api-handbook', | ||
'cli-handbook', | ||
'adv-admin-handbook', | ||
); | ||
|
||
$post_type = $block->context['postType']; | ||
$post_id = $block->context['postId']; | ||
|
||
if ( | ||
! isset( $post_id ) | ||
|| ! isset( $post_type ) | ||
|| ! in_array( $post_type, $github_handbooks, true ) | ||
) { | ||
return ''; | ||
} | ||
|
||
$title = get_the_title( $post_id ); | ||
|
||
$content = sprintf( | ||
do_blocks( | ||
'<!-- wp:group {"style":{"spacing":{"blockGap":"0"}},"layout":{"type":"constrained"}} --> | ||
<div class="wp-block-group"> | ||
<!-- wp:paragraph {"style":{"typography":{"fontStyle":"normal","fontWeight":"700"}}} --> | ||
<p style="font-style:normal;font-weight:700">%1$s</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:paragraph {"className":"external-link"} --> | ||
<p class="external-link"><a href="[article_edit_link]">%2$s</a></p> | ||
<!-- /wp:paragraph --> | ||
</div> | ||
<!-- /wp:group -->' | ||
), | ||
esc_html__( 'Edit article', 'wporg' ), | ||
sprintf( | ||
/* translators: %s: article title */ | ||
__( 'Improve it on GitHub<span class="screen-reader-text">: %s</span>', 'wporg' ), | ||
esc_html( $title ) | ||
) | ||
); | ||
|
||
if ( 'blocks-handbook' !== $post_type ) { | ||
$content .= sprintf( | ||
do_blocks( | ||
'<!-- wp:group {"style":{"spacing":{"blockGap":"0"}},"layout":{"type":"constrained"}} --> | ||
<div class="wp-block-group"> | ||
<!-- wp:paragraph {"style":{"typography":{"fontStyle":"normal","fontWeight":"700"}}} --> | ||
<p style="font-style:normal;font-weight:700">%1$s</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:paragraph {"className":"external-link"} --> | ||
<p class="external-link"><a href="[article_changelog_link]">%2$s</a></p> | ||
<!-- /wp:paragraph --> | ||
</div> | ||
<!-- /wp:group -->' | ||
), | ||
esc_html__( 'Changelog', 'wporg' ), | ||
sprintf( | ||
/* translators: %s: article title */ | ||
__( 'See list of changes<span class="screen-reader-text">: %s</span>', 'wporg' ), | ||
esc_html( $title ) | ||
) | ||
); | ||
} | ||
|
||
return $content; | ||
} |
17 changes: 17 additions & 0 deletions
17
source/wp-content/themes/wporg-developer-2023/src/article-meta-github/index.js
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,17 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Edit from '../shared/dynamic-edit'; | ||
import metadata from './block.json'; | ||
|
||
registerBlockType( metadata.name, { | ||
/** | ||
* @see ./edit.js | ||
*/ | ||
edit: Edit, | ||
} ); |
40 changes: 0 additions & 40 deletions
40
source/wp-content/themes/wporg-developer-2023/templates/single-handbook-github.html
This file was deleted.
Oops, something went wrong.