yoastseo
Version:
Yoast client-side content analysis
40 lines (38 loc) • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _countWords = _interopRequireDefault(require("../helpers/word/countWords.js"));
var _htmlParser = _interopRequireWildcard(require("../helpers/html/htmlParser"));
var _helpers = require("../helpers");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* A result of the word count calculation.
*
* @typedef WordCountResult
* @property {string} text The text with all HTML blocks removed and shortcodes filtered out.
* @property {number} count The number of words found in the text.
* @property {string} unit The unit used in the text length calculations, always "word".
*/
/**
* Count the words in the text.
*
* @param {Paper} paper The Paper object.
*
* @returns {WordCountResult} The number of words found in the text, plus "word" as the unit used in calculating the text length.
*/
function _default(paper) {
let text = paper.getText();
const customIgnoredClasses = _htmlParser.IGNORED_CLASSES.filter(c => c !== "yoast-ai-summarize");
text = (0, _htmlParser.default)(text, customIgnoredClasses);
text = (0, _helpers.filterShortcodesFromHTML)(text, paper._attributes && paper._attributes.shortcodes);
return {
text: text,
count: (0, _countWords.default)(text),
unit: "word"
};
}
//# sourceMappingURL=wordCountInText.js.map