Skip to content
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

Latest posts: make more link consistent between frontend and editor #51190

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -479,15 +480,22 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
.trim()
.split( ' ', excerptLength )
.join( ' ' ) }
{ /* translators: excerpt truncation character, default … */ }
{ __( ' … ' ) }
<a
href={ post.link }
rel="noopener noreferrer"
onClick={ showRedirectionPreventedNotice }
>
{ __( 'Read more' ) }
</a>
{ createInterpolateElement(
/* translators: excerpt truncation character, default … */
__( ' … <a>Read more</a>' ),
Copy link
Member Author

@ramonjd ramonjd Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this for i18n. Locales should be able to determine where the ellipsis is, if at all.

It's not the subject of the bug report however and can be rolled back, and the backend changed to match.

{
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
href={ post.link }
rel="noopener noreferrer"
onClick={
showRedirectionPreventedNotice
}
/>
),
}
) }
</>
) : (
excerpt
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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( __( ' … <a href="%1$s" rel="noopener noreferrer">Read more</a>', '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' );
}
Expand Down