UNPKG

yoastseo

Version:

Yoast client-side content analysis

113 lines (108 loc) 4.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _i18n = require("@wordpress/i18n"); var _lodash = require("lodash"); var _assessment = _interopRequireDefault(require("../assessment")); var _helpers = require("../../../helpers"); var _AssessmentResult = _interopRequireDefault(require("../../../values/AssessmentResult")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * @typedef {import("../../../languageProcessing/AbstractResearcher").default } Researcher * @typedef {import("../../../languageProcessing/researches/getLinkStatistics").LinkStatistics} LinkStatistics * @typedef {import("../../../values/").Paper } Paper */ /** * Assessment for calculating the outbound links in the text. */ class OutboundLinksAssessment extends _assessment.default { /** * Sets the identifier and the config. * * @param {Object} [config] The configuration to use. */ constructor(config = {}) { super(); const defaultConfig = { scores: { noLinks: 3, allNofollowed: 7, someNoFollowed: 8, allFollowed: 9 }, urlTitle: (0, _helpers.createAnchorOpeningTag)("https://yoa.st/34f"), urlCallToAction: (0, _helpers.createAnchorOpeningTag)("https://yoa.st/34g") }; this.identifier = "externalLinks"; this._config = (0, _lodash.merge)(defaultConfig, config); } /** * Runs the getLinkStatistics module, based on this returns an assessment result with score. * * @param {Paper} paper The paper to use for the assessment. * @param {Researcher} researcher The researcher used for calling research. * * @returns {AssessmentResult} The assessment result. */ getResult(paper, researcher) { const linkStatistics = researcher.getResearch("getLinkStatistics"); const assessmentResult = new _AssessmentResult.default(); if (!(0, _lodash.isEmpty)(linkStatistics)) { assessmentResult.setScore(this.calculateScore(linkStatistics)); assessmentResult.setText(this.translateScore(linkStatistics)); } return assessmentResult; } /** * Returns a score based on the linkStatistics object. * * @param {LinkStatistics} linkStatistics The object with all link statistics. * * @returns {number} The calculated score. */ calculateScore(linkStatistics) { if (linkStatistics.externalTotal === 0) { return this._config.scores.noLinks; } if (linkStatistics.externalNofollow === linkStatistics.externalTotal) { return this._config.scores.allNofollowed; } if (linkStatistics.externalDofollow < linkStatistics.externalTotal) { return this._config.scores.someNoFollowed; } if (linkStatistics.externalDofollow === linkStatistics.externalTotal) { return this._config.scores.allFollowed; } return 0; } /** * Translates the score to a message the user can understand. * * @param {LinkStatistics} linkStatistics The object with all link statistics. * * @returns {string} The translated string. */ translateScore(linkStatistics) { if (linkStatistics.externalTotal === 0) { return (0, _i18n.sprintf)(/* translators: %1$s and %2$s expand to links on yoast.com, %3$s expands to the anchor end tag */ (0, _i18n.__)("%1$sOutbound links%3$s: No outbound links appear in this page. %2$sAdd some%3$s!", "wordpress-seo"), this._config.urlTitle, this._config.urlCallToAction, "</a>"); } if (linkStatistics.externalNofollow === linkStatistics.externalTotal) { return (0, _i18n.sprintf)(/* translators: %1$s and %2$s expand to links on yoast.com, %3$s expands to the anchor end tag */ (0, _i18n.__)("%1$sOutbound links%3$s: All outbound links on this page are nofollowed. %2$sAdd some normal links%3$s.", "wordpress-seo"), this._config.urlTitle, this._config.urlCallToAction, "</a>"); } if (linkStatistics.externalDofollow === linkStatistics.externalTotal) { return (0, _i18n.sprintf)(/* translators: %1$s expands to a link on yoast.com, %2$s expands to the anchor end tag */ (0, _i18n.__)("%1$sOutbound links%2$s: Good job!", "wordpress-seo"), this._config.urlTitle, "</a>"); } if (linkStatistics.externalDofollow < linkStatistics.externalTotal) { return (0, _i18n.sprintf)(/* translators: %1$s expands to a link on yoast.com, %2$s expands to the anchor end tag */ (0, _i18n.__)("%1$sOutbound links%2$s: There are both nofollowed and normal outbound links on this page. Good job!", "wordpress-seo"), this._config.urlTitle, "</a>"); } return ""; } } exports.default = OutboundLinksAssessment; //# sourceMappingURL=OutboundLinksAssessment.js.map