UNPKG

yoastseo

Version:

Yoast client-side content analysis

35 lines (33 loc) 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var _lodash = require("lodash"); var _getAltAttribute = _interopRequireDefault(require("../image/getAltAttribute")); var _quotes = require("../sanitize/quotes"); var _parseSlug = _interopRequireDefault(require("../url/parseSlug")); var _getWords = _interopRequireDefault(require("../word/getWords")); var _getImagesInTree = _interopRequireDefault(require("../image/getImagesInTree")); var _wordBoundariesWithoutPunctuation = require("../../../config/wordBoundariesWithoutPunctuation"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * Gets all words found in the text, title, slug and meta description of a given paper. * * @param {Paper} paper The paper for which to get the words. * @param {boolean} areHyphensWordBoundaries Whether hyphens should be treated as word boundaries. * * @returns {string[]} All words found. */ function _default(paper, areHyphensWordBoundaries) { const paperText = paper.getText(); const altTagsInText = (0, _getImagesInTree.default)(paper).map(image => (0, _getAltAttribute.default)(image)); const paperContent = [paperText, paper.getTitle(), paper.getSlug(), (0, _parseSlug.default)(paper.getSlug()), paper.getDescription(), altTagsInText.join(" ")].join(" "); /* * If hyphens should be treated as word boundaries, pass a custom word boundary regex string that includes whitespaces, * hyphens (u002d), and en-dashes (u2013). Otherwise, pass a regex that includes only whitespaces and en-dashes. */ const words = areHyphensWordBoundaries ? (0, _getWords.default)(paperContent, _wordBoundariesWithoutPunctuation.WORD_BOUNDARY_WITH_HYPHEN) : (0, _getWords.default)(paperContent, _wordBoundariesWithoutPunctuation.WORD_BOUNDARY_WITHOUT_HYPHEN); return words.map(word => (0, _quotes.normalizeSingle)((0, _lodash.escapeRegExp)(word))); } //# sourceMappingURL=getAllWordsFromPaper.js.map