From ed5ce8f44d9a6130035bfb7aa9c6180801faf362 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 2 Jun 2023 15:08:31 +1000 Subject: [PATCH] This commit makes rendering Read more on latest post excerpts more consistent ensuring that the ellipsis and "Read more" appear in the editor and frontend, and that they are also translatable. --- .../block-library/src/latest-posts/edit.js | 26 ++++++++++++------- .../block-library/src/latest-posts/index.php | 8 ++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/block-library/src/latest-posts/edit.js b/packages/block-library/src/latest-posts/edit.js index 45266f6ab94c4e..8fcc2cc5b1ddda 100644 --- a/packages/block-library/src/latest-posts/edit.js +++ b/packages/block-library/src/latest-posts/edit.js @@ -32,6 +32,7 @@ import { pin, list, grid } from '@wordpress/icons'; import { store as coreStore } from '@wordpress/core-data'; import { store as noticeStore } from '@wordpress/notices'; import { useInstanceId } from '@wordpress/compose'; +import { createInterpolateElement } from '@wordpress/element'; /** * Internal dependencies @@ -479,15 +480,22 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) { .trim() .split( ' ', excerptLength ) .join( ' ' ) } - { /* translators: excerpt truncation character, default … */ } - { __( ' … ' ) } - - { __( 'Read more' ) } - + { createInterpolateElement( + /* translators: excerpt truncation character, default … */ + __( ' … Read more' ), + { + a: ( + // eslint-disable-next-line jsx-a11y/anchor-has-content + + ), + } + ) } ) : ( excerpt diff --git a/packages/block-library/src/latest-posts/index.php b/packages/block-library/src/latest-posts/index.php index d3945ee2c9ee2f..746133ec7a8989 100644 --- a/packages/block-library/src/latest-posts/index.php +++ b/packages/block-library/src/latest-posts/index.php @@ -48,6 +48,14 @@ function render_block_core_latest_posts( $attributes ) { $block_core_latest_posts_excerpt_length = $attributes['excerptLength']; add_filter( 'excerpt_length', 'block_core_latest_posts_get_excerpt_length', 20 ); + $filter_latest_posts_excerpt_more = static function( $more ) use ( $attributes ) { + $use_excerpt = 'excerpt' === $attributes['displayPostContentRadio']; + /* translators: %1$s is a URL to a post, excerpt truncation character, default … */ + return $use_excerpt ? sprintf( __( ' … Read more', 'gutenberg' ), esc_url( get_permalink() ) ) : $more; + }; + + add_filter( 'excerpt_more', $filter_latest_posts_excerpt_more ); + if ( isset( $attributes['categories'] ) ) { $args['category__in'] = array_column( $attributes['categories'], 'id' ); }