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

Convert Sentence length and paragraph length to use HTML parser and enable AI button for both assessments #21866

Open
wants to merge 16 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into html-pars…
…er/paragraph-length
  • Loading branch information
FAMarfuaty committed Nov 27, 2024
commit 7ca0e32cf4b52f1b8826d9f070f7dc36efb6fae6
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,58 @@ export default class ParagraphTooLongAssessment extends Assessment {
return assessmentResult;
}

const tooLongParagraphs = this.getTooLongParagraphs( paragraphsLength, config );
assessmentResult.setHasMarks( true );
assessmentResult.setText( sprintf(
/* translators: %1$s and %5$s expand to a link on yoast.com, %2$s expands to the anchor end tag,
%3$d expands to the number of paragraphs over the recommended word / character limit, %4$d expands to the word / character limit,
%6$s expands to the word 'words' or 'characters'. */
const wordFeedback = sprintf(
/* translators: %1$s and %5$s expand to links on yoast.com, %2$s expands to the anchor end tag,
%3$d expands to the number of paragraphs over the recommended limit, %4$d expands to the limit. */
_n(
"%1$sParagraph length%2$s: %3$d of the paragraphs contains more than the recommended maximum of %4$d %6$s. %5$sShorten your paragraphs%2$s!",
"%1$sParagraph length%2$s: %3$d of the paragraphs contain more than the recommended maximum of %4$d %6$s. %5$sShorten your paragraphs%2$s!",
"%1$sParagraph length%2$s: %3$d of the paragraphs contains more than the recommended maximum number of words (%4$d). %5$sShorten your paragraphs%2$s!",
"%1$sParagraph length%2$s: %3$d of the paragraphs contain more than the recommended maximum number of words (%4$d). %5$sShorten your paragraphs%2$s!",
tooLongParagraphs.length,
"wordpress-seo"
),
config.urlTitle,
"</a>",
tooLongParagraphs.length,
config.parameters.recommendedLength,
config.urlCallToAction,
this._config.countTextIn
) );
return assessmentResult;
config.urlCallToAction
);

const characterFeedback = sprintf(
/* translators: %1$s and %5$s expand to links on yoast.com, %2$s expands to the anchor end tag,
%3$d expands to the number of paragraphs over the recommended limit, %4$d expands to the limit. */
_n(
"%1$sParagraph length%2$s: %3$d of the paragraphs contains more than the recommended maximum number of characters (%4$d). %5$sShorten your paragraphs%2$s!",
"%1$sParagraph length%2$s: %3$d of the paragraphs contain more than the recommended maximum number of characters (%4$d). %5$sShorten your paragraphs%2$s!",
tooLongParagraphs.length,
"wordpress-seo"
),
config.urlTitle,
"</a>",
tooLongParagraphs.length,
config.parameters.recommendedLength,
config.urlCallToAction
);

return {
score: score,
hasMarks: true,
text: config.countCharacters ? characterFeedback : wordFeedback,
};
}

/**
* Sort the paragraphs based on word count.
*
* @param {Array} paragraphs The array with paragraphs.
*
* @returns {Array} The array sorted on word counts.
*/
sortParagraphs( paragraphs ) {
return paragraphs.sort(
function( a, b ) {
return b.countLength - a.countLength;
}
);
}

/**
Expand Down Expand Up @@ -176,10 +208,7 @@ export default class ParagraphTooLongAssessment extends Assessment {
*/
getResult( paper, researcher ) {
const paragraphsLength = researcher.getResearch( "getParagraphLength" );
const countTextInCharacters = researcher.getConfig( "countCharacters" );
if ( countTextInCharacters ) {
this._config.countTextIn = __( "characters", "wordpress-seo" );
}
this._config.countCharacters = !! researcher.getConfig( "countCharacters" );

return this.calculateResult( paragraphsLength, this.getConfig( researcher ) );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { __, sprintf } from "@wordpress/i18n";
import { __, _n, sprintf } from "@wordpress/i18n";
import { merge } from "lodash";

import Assessment from "../assessment";
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.