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 block] Option to always show the [Read more ...] #51213

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
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
53 changes: 20 additions & 33 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ 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 @@ -470,37 +469,6 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
/>
);

const needsReadMore =
excerptLength < excerpt.trim().split( ' ' ).length &&
post.excerpt.raw === '';

const postExcerpt = needsReadMore ? (
<>
{ excerpt
.trim()
.split( ' ', excerptLength )
.join( ' ' ) }
{ createInterpolateElement(
/* translators: excerpt truncation character, default … */
__( ' … <a>Read more</a>' ),
{
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
href={ post.link }
rel="noopener noreferrer"
onClick={
showRedirectionPreventedNotice
}
/>
),
}
) }
</>
) : (
excerpt
);

return (
<li key={ post.id }>
{ renderFeaturedImage && (
Expand Down Expand Up @@ -555,7 +523,26 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
{ displayPostContent &&
displayPostContentRadio === 'excerpt' && (
<div className="wp-block-latest-posts__post-excerpt">
{ postExcerpt }
{ excerpt
.trim()
.split( ' ', excerptLength )
.join( ' ' ) }
{ /* translators: excerpt truncation character, default … */ }
Copy link
Contributor

Choose a reason for hiding this comment

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

The ellipsis is not used anymore so the translators comment should be removed.

{ <br></br> }
<a
href={ post.link }
rel="noopener noreferrer"
onClick={
showRedirectionPreventedNotice
}
aria-label={ sprintf(
/* translators: byline. %s: Read more about current post. */
__( 'Read more about %s' ),
titleTrimmed
) }
>
{ __( 'Read more' ) }
</a>
</div>
) }
{ displayPostContent &&
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ function render_block_core_latest_posts( $attributes ) {
'<div class="wp-block-latest-posts__post-excerpt">%1$s</div>',
$trimmed_excerpt
);
$list_items_markup .= sprintf(
'<a class="wp-block-latest-posts__post-read-more" href="%1$s" aria-label="%2$s">%3$s</a>',
esc_url( $post_link ),
esc_attr( __( 'Read more about ' . $title ) ),
__( 'Read more' )
);
}

if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`combine-assets\` should pro
]
`;

exports[`DependencyExtractionWebpackPlugin Webpack \`dynamic-import\` should produce expected output: Asset file 'assets.php' should match snapshot 1`] = `
"<?php return array('fileA.js' => array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'cbe985cf6e1a25d848e5'), 'fileB.js' => array('dependencies' => array('wp-token-list'), 'version' => '7f3970305cf0aecb54ab'));
"
`;

exports[`DependencyExtractionWebpackPlugin Webpack \`dynamic-import\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('wp-blob'), 'version' => 'c8be4fceac30d1d00ca7');
"
Expand All @@ -49,6 +54,19 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`dynamic-import\` should pro
]
`;

exports[`DependencyExtractionWebpackPlugin Webpack \`dynamic-import\` should produce expected output: External modules should match snapshot 2`] = `
[
{
"externalType": "window",
"request": [
"wp",
"blob",
],
"userRequest": "@wordpress/blob",
},
]
`;

exports[`DependencyExtractionWebpackPlugin Webpack \`function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '9b7ebe61044661fdabda');
"
Expand Down Expand Up @@ -290,6 +308,11 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress-require\` should
"
`;

exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress-require\` should produce expected output: Asset file 'main.asset.php' should match snapshot 2`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '40370eb4ce6428562da6');
"
`;

exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress-require\` should produce expected output: External modules should match snapshot 1`] = `
[
{
Expand All @@ -307,3 +330,21 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress-require\` should
},
]
`;

exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress-require\` should produce expected output: External modules should match snapshot 2`] = `
[
{
"externalType": "window",
"request": "lodash",
"userRequest": "lodash",
},
{
"externalType": "window",
"request": [
"wp",
"blob",
],
"userRequest": "@wordpress/blob",
},
]
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CustomFieldsConfirmation submits the toggle-custom-fields-form 1`] = `<div />`;

exports[`CustomFieldsConfirmation submits the toggle-custom-fields-form 2`] = `<div />`;

exports[`EnableCustomFieldsOption renders a checked checkbox and a confirmation message when toggled on 1`] = `
.emotion-0 {
font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',sans-serif;
Expand Down