axyseo 2025.1.0-blog.2 → 2025.1.0-blog.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/languageProcessing/researches/getSentenceBeginnings.js +16 -9
- package/build/cjs/languageProcessing/researches/getSentenceBeginnings.js.map +1 -1
- package/build/cjs/scoring/assessments/seo/ImagesInContentAssessment.js +11 -5
- package/build/cjs/scoring/assessments/seo/ImagesInContentAssessment.js.map +1 -1
- package/build/esm/languageProcessing/researches/getSentenceBeginnings.js +16 -9
- package/build/esm/languageProcessing/researches/getSentenceBeginnings.js.map +1 -1
- package/build/esm/scoring/assessments/seo/ImagesInContentAssessment.js +10 -5
- package/build/esm/scoring/assessments/seo/ImagesInContentAssessment.js.map +1 -1
- package/package.json +1 -1
|
@@ -61,7 +61,7 @@ const compareFirstWords = function (sentenceBeginnings, sentences) {
|
|
|
61
61
|
* @param {string} sentence The sentence to retrieve the first word from.
|
|
62
62
|
* @param {Array} firstWordExceptions First word exceptions to match against.
|
|
63
63
|
* @param {Array} secondWordExceptions Second word exceptions to match against.
|
|
64
|
-
* @param {function}
|
|
64
|
+
* @param {function} getWordsCustomHelper The language-specific helper function to retrieve words from text.
|
|
65
65
|
*
|
|
66
66
|
* @returns {string} The first word of the sentence.
|
|
67
67
|
*/
|
|
@@ -108,15 +108,22 @@ function _default(paper, researcher) {
|
|
|
108
108
|
// Exclude text inside tables.
|
|
109
109
|
text = text.replace(/<figure class='wp-block-table'>.*<\/figure>/gs, '');
|
|
110
110
|
let sentences = (0, _getSentences.default)(text, memoizedTokenizer);
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const sentenceData = sentences.map(function (sentence) {
|
|
112
|
+
const beginning = getSentenceBeginning(sentence, firstWordExceptions, secondWordExceptions, getWordsCustomHelper);
|
|
113
|
+
return {
|
|
114
|
+
sentence,
|
|
115
|
+
beginning
|
|
116
|
+
};
|
|
113
117
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
+
const filteredSentenceData = sentenceData.filter(function (item) {
|
|
119
|
+
if (!item.beginning) return false;
|
|
120
|
+
const stripped = (0, _stripHTMLTags.stripFullTags)((0, _stripSpaces.default)(item.sentence));
|
|
121
|
+
const strippedNoSpaces = stripped.replace(/\s+/g, '');
|
|
122
|
+
const isDigitsOnly = strippedNoSpaces.length > 0 && /^[0-9]+$/.test(strippedNoSpaces);
|
|
123
|
+
return !isDigitsOnly;
|
|
118
124
|
});
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
const filteredSentences = filteredSentenceData.map(item => item.sentence);
|
|
126
|
+
const sentenceBeginnings = filteredSentenceData.map(item => item.beginning);
|
|
127
|
+
return compareFirstWords(sentenceBeginnings, filteredSentences);
|
|
121
128
|
}
|
|
122
129
|
//# sourceMappingURL=getSentenceBeginnings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSentenceBeginnings.js","names":["_getWords","_interopRequireDefault","require","_getSentences","_stripSpaces","_stripHTMLTags","_lodash","_htmlParser","_helpers","_stripNonTextTags","e","__esModule","default","startsWithSameWord","currentSentenceBeginning","nextSentenceBeginning","isEmpty","compareFirstWords","sentenceBeginnings","sentences","consecutiveFirstWords","foundSentences","sameBeginnings","forEach","beginning","i","push","word","count","getSentenceBeginning","sentence","firstWordExceptions","secondWordExceptions","getWordsCustomHelper","stripped","stripTags","stripSpaces","words","getWords","filter","test","length","firstWord","toLocaleLowerCase","indexOf","includes","_default","paper","researcher","getConfig","getHelper","memoizedTokenizer","text","getText","removeHtmlBlocks","stripNonTextTags","filterShortcodesFromHTML","_attributes","shortcodes","replace","getSentences","map"],"sources":["../../../../src/languageProcessing/researches/getSentenceBeginnings.js"],"sourcesContent":["import getWords from '../helpers/word/getWords.js';\nimport getSentences from '../helpers/sentence/getSentences';\nimport stripSpaces from '../helpers/sanitize/stripSpaces.js';\nimport {stripFullTags as stripTags} from '../helpers/sanitize/stripHTMLTags.js';\n\nimport {filter, forEach, isEmpty} from 'lodash';\nimport removeHtmlBlocks from '../helpers/html/htmlParser';\nimport {filterShortcodesFromHTML} from '../helpers';\nimport stripNonTextTags from '@axyseo/languageProcessing/helpers/sanitize/stripNonTextTags';\n\n/**\n * Compares the first word of each sentence with the first word of the following sentence.\n *\n * @param {string} currentSentenceBeginning The first word of the current sentence.\n * @param {string} nextSentenceBeginning The first word of the next sentence.\n * @returns {boolean} Returns true if sentence beginnings match.\n */\nconst startsWithSameWord = function(currentSentenceBeginning, nextSentenceBeginning) {\n return !isEmpty(currentSentenceBeginning) && currentSentenceBeginning === nextSentenceBeginning;\n};\n\n/**\n * Counts the number of similar sentence beginnings.\n *\n * @param {Array} sentenceBeginnings The array containing the first word of each sentence.\n * @param {Array} sentences The array containing all sentences.\n * @returns {Array} The array containing the objects containing the first words and the corresponding counts.\n */\nconst compareFirstWords = function(sentenceBeginnings, sentences) {\n const consecutiveFirstWords = [];\n let foundSentences = [];\n let sameBeginnings = 1;\n\n forEach(sentenceBeginnings, function(beginning, i) {\n const currentSentenceBeginning = beginning;\n const nextSentenceBeginning = sentenceBeginnings[i + 1];\n foundSentences.push(sentences[i]);\n\n if (startsWithSameWord(currentSentenceBeginning, nextSentenceBeginning)) {\n sameBeginnings++;\n } else {\n consecutiveFirstWords.push({\n word: currentSentenceBeginning,\n count: sameBeginnings,\n sentences: foundSentences\n });\n sameBeginnings = 1;\n foundSentences = [];\n }\n });\n\n return consecutiveFirstWords;\n};\n\n/**\n * Retrieves the first word from the sentence. If the first or second word is on an exception list of words that should not be considered as sentence\n * beginnings, the following word is also retrieved.\n *\n * @param {string} sentence The sentence to retrieve the first word from.\n * @param {Array} firstWordExceptions First word exceptions to match against.\n * @param {Array} secondWordExceptions Second word exceptions to match against.\n * @param {function}\tgetWordsCustomHelper The language-specific helper function to retrieve words from text.\n *\n * @returns {string} The first word of the sentence.\n */\nfunction getSentenceBeginning(\n sentence,\n firstWordExceptions,\n secondWordExceptions,\n getWordsCustomHelper\n) {\n const stripped = stripTags(stripSpaces(sentence));\n let words = getWordsCustomHelper ? getWordsCustomHelper(stripped) : getWords(stripped);\n\n words = words.filter(word => /^\\p{L}/u.test(word));\n\n if (words.length === 0) {\n return '';\n }\n\n let firstWord = words[0].toLocaleLowerCase();\n\n if (firstWordExceptions.indexOf(firstWord) > -1 && words.length > 1) {\n firstWord = firstWord + ' ' + words[1];\n if (secondWordExceptions) {\n if (secondWordExceptions.includes(words[1])) {\n firstWord = firstWord + ' ' + words[2];\n }\n }\n }\n\n return firstWord;\n}\n\n/**\n * Gets the first word of each sentence from the text, and returns an object containing the first word of each sentence and the corresponding counts.\n *\n * @param {Paper} paper The Paper object to get the text from.\n * @param {Researcher} researcher The researcher this research is a part of.\n *\n * @returns {Object} The object containing the first word of each sentence and the corresponding counts.\n */\nexport default function(paper, researcher) {\n const firstWordExceptions = researcher.getConfig('firstWordExceptions');\n const secondWordExceptions = researcher.getConfig('secondWordExceptions');\n const getWordsCustomHelper = researcher.getHelper('getWordsCustomHelper');\n const memoizedTokenizer = researcher.getHelper('memoizedTokenizer');\n\n let text = paper.getText();\n text = removeHtmlBlocks(text);\n text = stripNonTextTags(text);\n text = filterShortcodesFromHTML(text, paper._attributes && paper._attributes.shortcodes);\n\n // Remove any HTML whitespace padding and replace it with a single whitespace.\n text = text.replace(/[\\s\\n]+/g, ' ');\n\n // Exclude text inside tables.\n text = text.replace(/<figure class='wp-block-table'>.*<\\/figure>/gs, '');\n\n let sentences = getSentences(text, memoizedTokenizer);\n\n let sentenceBeginnings = sentences.map(function(sentence) {\n return getSentenceBeginning(\n sentence,\n firstWordExceptions,\n secondWordExceptions,\n getWordsCustomHelper\n );\n });\n\n sentences = sentences.filter(function(sentence) {\n const stripped = stripSpaces(sentence);\n const words = getWordsCustomHelper ? getWordsCustomHelper(stripped) : getWords(stripped);\n return words.length > 0;\n });\n sentenceBeginnings = filter(sentenceBeginnings);\n\n return compareFirstWords(sentenceBeginnings, sentences);\n}\n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QAAQ,CAAC;IACxF,OAAOG,KAAK,CAACI,MAAM,GAAG,CAAC;EACzB,CAAC,CAAC;EACFvB,kBAAkB,GAAG,IAAAqB,cAAM,EAACrB,kBAAkB,CAAC;EAE/C,OAAOD,iBAAiB,CAACC,kBAAkB,EAAEC,SAAS,CAAC;AACzD","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"getSentenceBeginnings.js","names":["_getWords","_interopRequireDefault","require","_getSentences","_stripSpaces","_stripHTMLTags","_lodash","_htmlParser","_helpers","_stripNonTextTags","e","__esModule","default","startsWithSameWord","currentSentenceBeginning","nextSentenceBeginning","isEmpty","compareFirstWords","sentenceBeginnings","sentences","consecutiveFirstWords","foundSentences","sameBeginnings","forEach","beginning","i","push","word","count","getSentenceBeginning","sentence","firstWordExceptions","secondWordExceptions","getWordsCustomHelper","stripped","stripTags","stripSpaces","words","getWords","filter","test","length","firstWord","toLocaleLowerCase","indexOf","includes","_default","paper","researcher","getConfig","getHelper","memoizedTokenizer","text","getText","removeHtmlBlocks","stripNonTextTags","filterShortcodesFromHTML","_attributes","shortcodes","replace","getSentences","sentenceData","map","filteredSentenceData","item","strippedNoSpaces","isDigitsOnly","filteredSentences"],"sources":["../../../../src/languageProcessing/researches/getSentenceBeginnings.js"],"sourcesContent":["import getWords from '../helpers/word/getWords.js';\nimport getSentences from '../helpers/sentence/getSentences';\nimport stripSpaces from '../helpers/sanitize/stripSpaces.js';\nimport {stripFullTags as stripTags} from '../helpers/sanitize/stripHTMLTags.js';\n\nimport {filter, forEach, isEmpty} from 'lodash';\nimport removeHtmlBlocks from '../helpers/html/htmlParser';\nimport {filterShortcodesFromHTML} from '../helpers';\nimport stripNonTextTags from '@axyseo/languageProcessing/helpers/sanitize/stripNonTextTags';\n\n/**\n * Compares the first word of each sentence with the first word of the following sentence.\n *\n * @param {string} currentSentenceBeginning The first word of the current sentence.\n * @param {string} nextSentenceBeginning The first word of the next sentence.\n * @returns {boolean} Returns true if sentence beginnings match.\n */\nconst startsWithSameWord = function(currentSentenceBeginning, nextSentenceBeginning) {\n return !isEmpty(currentSentenceBeginning) && currentSentenceBeginning === nextSentenceBeginning;\n};\n\n/**\n * Counts the number of similar sentence beginnings.\n *\n * @param {Array} sentenceBeginnings The array containing the first word of each sentence.\n * @param {Array} sentences The array containing all sentences.\n * @returns {Array} The array containing the objects containing the first words and the corresponding counts.\n */\nconst compareFirstWords = function(sentenceBeginnings, sentences) {\n const consecutiveFirstWords = [];\n let foundSentences = [];\n let sameBeginnings = 1;\n\n forEach(sentenceBeginnings, function(beginning, i) {\n const currentSentenceBeginning = beginning;\n const nextSentenceBeginning = sentenceBeginnings[i + 1];\n foundSentences.push(sentences[i]);\n\n if (startsWithSameWord(currentSentenceBeginning, nextSentenceBeginning)) {\n sameBeginnings++;\n } else {\n consecutiveFirstWords.push({\n word: currentSentenceBeginning,\n count: sameBeginnings,\n sentences: foundSentences\n });\n sameBeginnings = 1;\n foundSentences = [];\n }\n });\n\n return consecutiveFirstWords;\n};\n\n/**\n * Retrieves the first word from the sentence. If the first or second word is on an exception list of words that should not be considered as sentence\n * beginnings, the following word is also retrieved.\n *\n * @param {string} sentence The sentence to retrieve the first word from.\n * @param {Array} firstWordExceptions First word exceptions to match against.\n * @param {Array} secondWordExceptions Second word exceptions to match against.\n * @param {function} getWordsCustomHelper The language-specific helper function to retrieve words from text.\n *\n * @returns {string} The first word of the sentence.\n */\nfunction getSentenceBeginning(\n sentence,\n firstWordExceptions,\n secondWordExceptions,\n getWordsCustomHelper\n) {\n const stripped = stripTags(stripSpaces(sentence));\n let words = getWordsCustomHelper ? getWordsCustomHelper(stripped) : getWords(stripped);\n\n words = words.filter(word => /^\\p{L}/u.test(word));\n\n if (words.length === 0) {\n return '';\n }\n\n let firstWord = words[0].toLocaleLowerCase();\n\n if (firstWordExceptions.indexOf(firstWord) > -1 && words.length > 1) {\n firstWord = firstWord + ' ' + words[1];\n if (secondWordExceptions) {\n if (secondWordExceptions.includes(words[1])) {\n firstWord = firstWord + ' ' + words[2];\n }\n }\n }\n\n return firstWord;\n}\n\n/**\n * Gets the first word of each sentence from the text, and returns an object containing the first word of each sentence and the corresponding counts.\n *\n * @param {Paper} paper The Paper object to get the text from.\n * @param {Researcher} researcher The researcher this research is a part of.\n *\n * @returns {Object} The object containing the first word of each sentence and the corresponding counts.\n */\nexport default function(paper, researcher) {\n const firstWordExceptions = researcher.getConfig('firstWordExceptions');\n const secondWordExceptions = researcher.getConfig('secondWordExceptions');\n const getWordsCustomHelper = researcher.getHelper('getWordsCustomHelper');\n const memoizedTokenizer = researcher.getHelper('memoizedTokenizer');\n\n let text = paper.getText();\n text = removeHtmlBlocks(text);\n text = stripNonTextTags(text);\n text = filterShortcodesFromHTML(text, paper._attributes && paper._attributes.shortcodes);\n\n // Remove any HTML whitespace padding and replace it with a single whitespace.\n text = text.replace(/[\\s\\n]+/g, ' ');\n\n // Exclude text inside tables.\n text = text.replace(/<figure class='wp-block-table'>.*<\\/figure>/gs, '');\n\n let sentences = getSentences(text, memoizedTokenizer);\n\n const sentenceData = sentences.map(function(sentence) {\n const beginning = getSentenceBeginning(\n sentence,\n firstWordExceptions,\n secondWordExceptions,\n getWordsCustomHelper\n );\n\n return {sentence, beginning};\n });\n\n const filteredSentenceData = sentenceData.filter(function(item) {\n if (!item.beginning) return false;\n\n const stripped = stripTags(stripSpaces(item.sentence));\n const strippedNoSpaces = stripped.replace(/\\s+/g, '');\n const isDigitsOnly = strippedNoSpaces.length > 0 && /^[0-9]+$/.test(strippedNoSpaces);\n\n return !isDigitsOnly;\n });\n\n const filteredSentences = filteredSentenceData.map(item => item.sentence);\n const sentenceBeginnings = filteredSentenceData.map(item => item.beginning);\n\n return compareFirstWords(sentenceBeginnings, filteredSentences);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA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,YAAY,GAAGD,gBAAgB,CAACxB,MAAM,GAAG,CAAC,IAAI,UAAU,CAACD,IAAI,CAACyB,gBAAgB,CAAC;IAErF,OAAO,CAACC,YAAY;EACtB,CAAC,CAAC;EAEF,MAAMC,iBAAiB,GAAGJ,oBAAoB,CAACD,GAAG,CAACE,IAAI,IAAIA,IAAI,CAAClC,QAAQ,CAAC;EACzE,MAAMZ,kBAAkB,GAAG6C,oBAAoB,CAACD,GAAG,CAACE,IAAI,IAAIA,IAAI,CAACxC,SAAS,CAAC;EAE3E,OAAOP,iBAAiB,CAACC,kBAAkB,EAAEiD,iBAAiB,CAAC;AACjE","ignoreList":[]}
|
|
@@ -9,6 +9,11 @@ var _assessment = _interopRequireDefault(require("../assessment"));
|
|
|
9
9
|
var _AssessmentResult = _interopRequireDefault(require("../../../values/AssessmentResult"));
|
|
10
10
|
var _analysis = require("../../../const/analysis");
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
const DEFAULT_TITLE = 'Images in content';
|
|
13
|
+
const DEFAULT_GOOD_TITLE = 'Images included';
|
|
14
|
+
const DEFAULT_GOOD_CONTENT = 'Images are included and well placed.';
|
|
15
|
+
const DEFAULT_BAD_CONTENT = 'This post is text heavy. Add images to break up sections and improve reading experience.';
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* Represents the assessment that checks if the text has any images present.
|
|
14
19
|
*/
|
|
@@ -28,12 +33,12 @@ class ImagesInContentAssessment extends _assessment.default {
|
|
|
28
33
|
ctaType: 'fix',
|
|
29
34
|
priority: 'high',
|
|
30
35
|
fixPosition: 'description',
|
|
31
|
-
title:
|
|
32
|
-
goodTitle:
|
|
36
|
+
title: DEFAULT_TITLE,
|
|
37
|
+
goodTitle: DEFAULT_GOOD_TITLE,
|
|
33
38
|
content: {
|
|
34
|
-
good:
|
|
39
|
+
good: DEFAULT_GOOD_CONTENT,
|
|
35
40
|
improve: '',
|
|
36
|
-
bad:
|
|
41
|
+
bad: DEFAULT_BAD_CONTENT
|
|
37
42
|
}
|
|
38
43
|
};
|
|
39
44
|
this.identifier = _analysis.IMAGES_IN_CONTENT_ID;
|
|
@@ -85,7 +90,8 @@ class ImagesInContentAssessment extends _assessment.default {
|
|
|
85
90
|
status = 'good';
|
|
86
91
|
}
|
|
87
92
|
const score = this.getScore(this._config.priority, status);
|
|
88
|
-
const
|
|
93
|
+
const shouldUseTitleForGood = this._config.title !== DEFAULT_TITLE && this._config.goodTitle === DEFAULT_GOOD_TITLE;
|
|
94
|
+
const title = status === 'good' ? shouldUseTitleForGood ? this._config.title : this._config.goodTitle || this._config.title : this._config.title;
|
|
89
95
|
return {
|
|
90
96
|
score,
|
|
91
97
|
status,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImagesInContentAssessment.js","names":["_lodash","require","_assessment","_interopRequireDefault","_AssessmentResult","_analysis","e","__esModule","default","ImagesInContentAssessment","Assessment","constructor","config","defaultConfig","id","IMAGES_IN_CONTENT_ID","docUrl","ctaType","priority","fixPosition","title","goodTitle","content","good","improve","bad","identifier","_config","merge","getResult","paper","researcher","imageCount","getResearch","assessmentResult","AssessmentResult","calculatedResult","calculateResult","setScore","score","setStatus","status","setTitle","isApplicable","hasText","getScore","exports"],"sources":["../../../../../src/scoring/assessments/seo/ImagesInContentAssessment.js"],"sourcesContent":["import {merge} from 'lodash';\nimport Assessment from '../assessment';\nimport AssessmentResult from '../../../values/AssessmentResult';\nimport {IMAGES_IN_CONTENT_ID} from '@axyseo/const/analysis';\n\n/**\n * Represents the assessment that checks if the text has any images present.\n */\nexport default class ImagesInContentAssessment extends Assessment {\n /**\n * Sets the identifier and the config.\n *\n * @param {object} config The configuration to use.\n *\n * @returns {void}\n */\n constructor(config = {}) {\n super();\n\n const defaultConfig = {\n id: IMAGES_IN_CONTENT_ID,\n docUrl: 'https://docs.avada.io/seo-suite-help-center/seo-audit/on-page-seo/checklist',\n ctaType: 'fix',\n priority: 'high',\n fixPosition: 'description',\n title:
|
|
1
|
+
{"version":3,"file":"ImagesInContentAssessment.js","names":["_lodash","require","_assessment","_interopRequireDefault","_AssessmentResult","_analysis","e","__esModule","default","DEFAULT_TITLE","DEFAULT_GOOD_TITLE","DEFAULT_GOOD_CONTENT","DEFAULT_BAD_CONTENT","ImagesInContentAssessment","Assessment","constructor","config","defaultConfig","id","IMAGES_IN_CONTENT_ID","docUrl","ctaType","priority","fixPosition","title","goodTitle","content","good","improve","bad","identifier","_config","merge","getResult","paper","researcher","imageCount","getResearch","assessmentResult","AssessmentResult","calculatedResult","calculateResult","setScore","score","setStatus","status","setTitle","isApplicable","hasText","getScore","shouldUseTitleForGood","exports"],"sources":["../../../../../src/scoring/assessments/seo/ImagesInContentAssessment.js"],"sourcesContent":["import {merge} from 'lodash';\nimport Assessment from '../assessment';\nimport AssessmentResult from '../../../values/AssessmentResult';\nimport {IMAGES_IN_CONTENT_ID} from '@axyseo/const/analysis';\n\nconst DEFAULT_TITLE = 'Images in content';\nconst DEFAULT_GOOD_TITLE = 'Images included';\nconst DEFAULT_GOOD_CONTENT = 'Images are included and well placed.';\nconst DEFAULT_BAD_CONTENT =\n 'This post is text heavy. Add images to break up sections and improve reading experience.';\n\n/**\n * Represents the assessment that checks if the text has any images present.\n */\nexport default class ImagesInContentAssessment extends Assessment {\n /**\n * Sets the identifier and the config.\n *\n * @param {object} config The configuration to use.\n *\n * @returns {void}\n */\n constructor(config = {}) {\n super();\n\n const defaultConfig = {\n id: IMAGES_IN_CONTENT_ID,\n docUrl: 'https://docs.avada.io/seo-suite-help-center/seo-audit/on-page-seo/checklist',\n ctaType: 'fix',\n priority: 'high',\n fixPosition: 'description',\n title: DEFAULT_TITLE,\n goodTitle: DEFAULT_GOOD_TITLE,\n content: {\n good: DEFAULT_GOOD_CONTENT,\n improve: '',\n bad: DEFAULT_BAD_CONTENT\n }\n };\n\n this.identifier = IMAGES_IN_CONTENT_ID;\n this._config = merge(defaultConfig, config);\n }\n\n /**\n * Execute the Assessment and return a result.\n *\n * @param {Paper} paper The Paper object to assess.\n * @param {Researcher} researcher The Researcher object containing all available researches.\n * @returns {AssessmentResult} The result of the assessment, containing both a score and a descriptive text.\n */\n getResult({paper, researcher}) {\n this.imageCount = researcher.getResearch('imageCount');\n\n const assessmentResult = new AssessmentResult({config: this._config});\n\n const calculatedResult = this.calculateResult();\n\n assessmentResult.setScore(calculatedResult.score);\n assessmentResult.setStatus(calculatedResult.status);\n assessmentResult.setTitle(calculatedResult.title);\n\n return assessmentResult;\n }\n\n /**\n * Checks whether the paper has text.\n *\n * @param {Paper} paper The paper to use for the assessment.\n *\n * @returns {boolean} True when there is text.\n */\n isApplicable(paper) {\n return paper.hasText();\n }\n\n /**\n *\n * @returns {{score: number, status: string, title: string}}\n */\n calculateResult() {\n let status = '';\n\n if (!this.imageCount || this.imageCount === 0) {\n status = 'improve';\n } else {\n status = 'good';\n }\n\n const score = this.getScore(this._config.priority, status);\n const shouldUseTitleForGood =\n this._config.title !== DEFAULT_TITLE && this._config.goodTitle === DEFAULT_GOOD_TITLE;\n const title =\n status === 'good'\n ? shouldUseTitleForGood\n ? this._config.title\n : this._config.goodTitle || this._config.title\n : this._config.title;\n\n return {\n score,\n status,\n title\n };\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAA4D,SAAAE,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE5D,MAAMG,aAAa,GAAG,mBAAmB;AACzC,MAAMC,kBAAkB,GAAG,iBAAiB;AAC5C,MAAMC,oBAAoB,GAAG,sCAAsC;AACnE,MAAMC,mBAAmB,GACvB,0FAA0F;;AAE5F;AACA;AACA;AACe,MAAMC,yBAAyB,SA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;AACF;AACA;AACA;EACEP,eAAeA,CAAA,EAAG;IAChB,IAAII,MAAM,GAAG,EAAE;IAEf,IAAI,CAAC,IAAI,CAACT,UAAU,IAAI,IAAI,CAACA,UAAU,KAAK,CAAC,EAAE;MAC7CS,MAAM,GAAG,SAAS;IACpB,CAAC,MAAM;MACLA,MAAM,GAAG,MAAM;IACjB;IAEA,MAAMF,KAAK,GAAG,IAAI,CAACM,QAAQ,CAAC,IAAI,CAAClB,OAAO,CAACT,QAAQ,EAAEuB,MAAM,CAAC;IAC1D,MAAMK,qBAAqB,GACzB,IAAI,CAACnB,OAAO,CAACP,KAAK,KAAKf,aAAa,IAAI,IAAI,CAACsB,OAAO,CAACN,SAAS,KAAKf,kBAAkB;IACvF,MAAMc,KAAK,GACTqB,MAAM,KAAK,MAAM,GACbK,qBAAqB,GACnB,IAAI,CAACnB,OAAO,CAACP,KAAK,GAClB,IAAI,CAACO,OAAO,CAACN,SAAS,IAAI,IAAI,CAACM,OAAO,CAACP,KAAK,GAC9C,IAAI,CAACO,OAAO,CAACP,KAAK;IAExB,OAAO;MACLmB,KAAK;MACLE,MAAM;MACNrB;IACF,CAAC;EACH;AACF;AAAC2B,OAAA,CAAA3C,OAAA,GAAAK,yBAAA","ignoreList":[]}
|
|
@@ -55,7 +55,7 @@ const compareFirstWords = function (sentenceBeginnings, sentences) {
|
|
|
55
55
|
* @param {string} sentence The sentence to retrieve the first word from.
|
|
56
56
|
* @param {Array} firstWordExceptions First word exceptions to match against.
|
|
57
57
|
* @param {Array} secondWordExceptions Second word exceptions to match against.
|
|
58
|
-
* @param {function}
|
|
58
|
+
* @param {function} getWordsCustomHelper The language-specific helper function to retrieve words from text.
|
|
59
59
|
*
|
|
60
60
|
* @returns {string} The first word of the sentence.
|
|
61
61
|
*/
|
|
@@ -102,15 +102,22 @@ export default function (paper, researcher) {
|
|
|
102
102
|
// Exclude text inside tables.
|
|
103
103
|
text = text.replace(/<figure class='wp-block-table'>.*<\/figure>/gs, '');
|
|
104
104
|
let sentences = getSentences(text, memoizedTokenizer);
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const sentenceData = sentences.map(function (sentence) {
|
|
106
|
+
const beginning = getSentenceBeginning(sentence, firstWordExceptions, secondWordExceptions, getWordsCustomHelper);
|
|
107
|
+
return {
|
|
108
|
+
sentence,
|
|
109
|
+
beginning
|
|
110
|
+
};
|
|
107
111
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
+
const filteredSentenceData = sentenceData.filter(function (item) {
|
|
113
|
+
if (!item.beginning) return false;
|
|
114
|
+
const stripped = stripTags(stripSpaces(item.sentence));
|
|
115
|
+
const strippedNoSpaces = stripped.replace(/\s+/g, '');
|
|
116
|
+
const isDigitsOnly = strippedNoSpaces.length > 0 && /^[0-9]+$/.test(strippedNoSpaces);
|
|
117
|
+
return !isDigitsOnly;
|
|
112
118
|
});
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
const filteredSentences = filteredSentenceData.map(item => item.sentence);
|
|
120
|
+
const sentenceBeginnings = filteredSentenceData.map(item => item.beginning);
|
|
121
|
+
return compareFirstWords(sentenceBeginnings, filteredSentences);
|
|
115
122
|
}
|
|
116
123
|
//# sourceMappingURL=getSentenceBeginnings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSentenceBeginnings.js","names":["getWords","getSentences","stripSpaces","stripFullTags","stripTags","filter","forEach","isEmpty","removeHtmlBlocks","filterShortcodesFromHTML","stripNonTextTags","startsWithSameWord","currentSentenceBeginning","nextSentenceBeginning","compareFirstWords","sentenceBeginnings","sentences","consecutiveFirstWords","foundSentences","sameBeginnings","beginning","i","push","word","count","getSentenceBeginning","sentence","firstWordExceptions","secondWordExceptions","getWordsCustomHelper","stripped","words","test","length","firstWord","toLocaleLowerCase","indexOf","includes","paper","researcher","getConfig","getHelper","memoizedTokenizer","text","getText","_attributes","shortcodes","replace","map"],"sources":["../../../../src/languageProcessing/researches/getSentenceBeginnings.js"],"sourcesContent":["import getWords from '../helpers/word/getWords.js';\nimport getSentences from '../helpers/sentence/getSentences';\nimport stripSpaces from '../helpers/sanitize/stripSpaces.js';\nimport {stripFullTags as stripTags} from '../helpers/sanitize/stripHTMLTags.js';\n\nimport {filter, forEach, isEmpty} from 'lodash';\nimport removeHtmlBlocks from '../helpers/html/htmlParser';\nimport {filterShortcodesFromHTML} from '../helpers';\nimport stripNonTextTags from '@axyseo/languageProcessing/helpers/sanitize/stripNonTextTags';\n\n/**\n * Compares the first word of each sentence with the first word of the following sentence.\n *\n * @param {string} currentSentenceBeginning The first word of the current sentence.\n * @param {string} nextSentenceBeginning The first word of the next sentence.\n * @returns {boolean} Returns true if sentence beginnings match.\n */\nconst startsWithSameWord = function(currentSentenceBeginning, nextSentenceBeginning) {\n return !isEmpty(currentSentenceBeginning) && currentSentenceBeginning === nextSentenceBeginning;\n};\n\n/**\n * Counts the number of similar sentence beginnings.\n *\n * @param {Array} sentenceBeginnings The array containing the first word of each sentence.\n * @param {Array} sentences The array containing all sentences.\n * @returns {Array} The array containing the objects containing the first words and the corresponding counts.\n */\nconst compareFirstWords = function(sentenceBeginnings, sentences) {\n const consecutiveFirstWords = [];\n let foundSentences = [];\n let sameBeginnings = 1;\n\n forEach(sentenceBeginnings, function(beginning, i) {\n const currentSentenceBeginning = beginning;\n const nextSentenceBeginning = sentenceBeginnings[i + 1];\n foundSentences.push(sentences[i]);\n\n if (startsWithSameWord(currentSentenceBeginning, nextSentenceBeginning)) {\n sameBeginnings++;\n } else {\n consecutiveFirstWords.push({\n word: currentSentenceBeginning,\n count: sameBeginnings,\n sentences: foundSentences\n });\n sameBeginnings = 1;\n foundSentences = [];\n }\n });\n\n return consecutiveFirstWords;\n};\n\n/**\n * Retrieves the first word from the sentence. If the first or second word is on an exception list of words that should not be considered as sentence\n * beginnings, the following word is also retrieved.\n *\n * @param {string} sentence The sentence to retrieve the first word from.\n * @param {Array} firstWordExceptions First word exceptions to match against.\n * @param {Array} secondWordExceptions Second word exceptions to match against.\n * @param {function}\tgetWordsCustomHelper The language-specific helper function to retrieve words from text.\n *\n * @returns {string} The first word of the sentence.\n */\nfunction getSentenceBeginning(\n sentence,\n firstWordExceptions,\n secondWordExceptions,\n getWordsCustomHelper\n) {\n const stripped = stripTags(stripSpaces(sentence));\n let words = getWordsCustomHelper ? getWordsCustomHelper(stripped) : getWords(stripped);\n\n words = words.filter(word => /^\\p{L}/u.test(word));\n\n if (words.length === 0) {\n return '';\n }\n\n let firstWord = words[0].toLocaleLowerCase();\n\n if (firstWordExceptions.indexOf(firstWord) > -1 && words.length > 1) {\n firstWord = firstWord + ' ' + words[1];\n if (secondWordExceptions) {\n if (secondWordExceptions.includes(words[1])) {\n firstWord = firstWord + ' ' + words[2];\n }\n }\n }\n\n return firstWord;\n}\n\n/**\n * Gets the first word of each sentence from the text, and returns an object containing the first word of each sentence and the corresponding counts.\n *\n * @param {Paper} paper The Paper object to get the text from.\n * @param {Researcher} researcher The researcher this research is a part of.\n *\n * @returns {Object} The object containing the first word of each sentence and the corresponding counts.\n */\nexport default function(paper, researcher) {\n const firstWordExceptions = researcher.getConfig('firstWordExceptions');\n const secondWordExceptions = researcher.getConfig('secondWordExceptions');\n const getWordsCustomHelper = researcher.getHelper('getWordsCustomHelper');\n const memoizedTokenizer = researcher.getHelper('memoizedTokenizer');\n\n let text = paper.getText();\n text = removeHtmlBlocks(text);\n text = stripNonTextTags(text);\n text = filterShortcodesFromHTML(text, paper._attributes && paper._attributes.shortcodes);\n\n // Remove any HTML whitespace padding and replace it with a single whitespace.\n text = text.replace(/[\\s\\n]+/g, ' ');\n\n // Exclude text inside tables.\n text = text.replace(/<figure class='wp-block-table'>.*<\\/figure>/gs, '');\n\n let sentences = getSentences(text, memoizedTokenizer);\n\n let sentenceBeginnings = sentences.map(function(sentence) {\n return getSentenceBeginning(\n sentence,\n firstWordExceptions,\n secondWordExceptions,\n getWordsCustomHelper\n );\n });\n\n sentences = sentences.filter(function(sentence) {\n const stripped = stripSpaces(sentence);\n const words = getWordsCustomHelper ? getWordsCustomHelper(stripped) : getWords(stripped);\n return words.length > 0;\n });\n sentenceBeginnings = filter(sentenceBeginnings);\n\n return compareFirstWords(sentenceBeginnings, sentences);\n}\n"],"mappings":"AAAA,OAAOA,QAAQ;AACf,OAAOC,YAAY;AACnB,OAAOC,WAAW;AAClB,SAAQC,aAAa,IAAIC,SAAS;AAElC,SAAQC,MAAM,EAAEC,OAAO,EAAEC,OAAO,QAAO,QAAQ;AAC/C,OAAOC,gBAAgB;AACvB,SAAQC,wBAAwB;AAChC,OAAOC,gBAAgB;;AAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG,SAAAA,CAASC,wBAAwB,EAAEC,qBAAqB,EAAE;EACnF,OAAO,CAACN,OAAO,CAACK,wBAAwB,CAAC,IAAIA,wBAAwB,KAAKC,qBAAqB;AACjG,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAG,SAAAA,CAASC,kBAAkB,EAAEC,SAAS,EAAE;EAChE,MAAMC,qBAAqB,GAAG,EAAE;EAChC,IAAIC,cAAc,GAAG,EAAE;EACvB,IAAIC,cAAc,GAAG,CAAC;EAEtBb,OAAO,CAACS,kBAAkB,EAAE,UAASK,SAAS,EAAEC,CAAC,EAAE;IACjD,MAAMT,wBAAwB,GAAGQ,SAAS;IAC1C,MAAMP,qBAAqB,GAAGE,kBAAkB,CAACM,CAAC,GAAG,CAAC,CAAC;IACvDH,cAAc,CAACI,IAAI,CAACN,SAAS,CAACK,CAAC,CAAC,CAAC;IAEjC,IAAIV,kBAAkB,CAACC,wBAAwB,EAAEC,qBAAqB,CAAC,EAAE;MACvEM,cAAc,EAAE;IAClB,CAAC,MAAM;MACLF,qBAAqB,CAACK,IAAI,CAAC;QACzBC,IAAI,EAAEX,wBAAwB;QAC9BY,KAAK,EAAEL,cAAc;QACrBH,SAAS,EAAEE;MACb,CAAC,CAAC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D,iBAAiB,CAACC,kBAAkB,EAAEC,SAAS,CAAC;AACzD","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"getSentenceBeginnings.js","names":["getWords","getSentences","stripSpaces","stripFullTags","stripTags","filter","forEach","isEmpty","removeHtmlBlocks","filterShortcodesFromHTML","stripNonTextTags","startsWithSameWord","currentSentenceBeginning","nextSentenceBeginning","compareFirstWords","sentenceBeginnings","sentences","consecutiveFirstWords","foundSentences","sameBeginnings","beginning","i","push","word","count","getSentenceBeginning","sentence","firstWordExceptions","secondWordExceptions","getWordsCustomHelper","stripped","words","test","length","firstWord","toLocaleLowerCase","indexOf","includes","paper","researcher","getConfig","getHelper","memoizedTokenizer","text","getText","_attributes","shortcodes","replace","sentenceData","map","filteredSentenceData","item","strippedNoSpaces","isDigitsOnly","filteredSentences"],"sources":["../../../../src/languageProcessing/researches/getSentenceBeginnings.js"],"sourcesContent":["import getWords from '../helpers/word/getWords.js';\nimport getSentences from '../helpers/sentence/getSentences';\nimport stripSpaces from '../helpers/sanitize/stripSpaces.js';\nimport {stripFullTags as stripTags} from '../helpers/sanitize/stripHTMLTags.js';\n\nimport {filter, forEach, isEmpty} from 'lodash';\nimport removeHtmlBlocks from '../helpers/html/htmlParser';\nimport {filterShortcodesFromHTML} from '../helpers';\nimport stripNonTextTags from '@axyseo/languageProcessing/helpers/sanitize/stripNonTextTags';\n\n/**\n * Compares the first word of each sentence with the first word of the following sentence.\n *\n * @param {string} currentSentenceBeginning The first word of the current sentence.\n * @param {string} nextSentenceBeginning The first word of the next sentence.\n * @returns {boolean} Returns true if sentence beginnings match.\n */\nconst startsWithSameWord = function(currentSentenceBeginning, nextSentenceBeginning) {\n return !isEmpty(currentSentenceBeginning) && currentSentenceBeginning === nextSentenceBeginning;\n};\n\n/**\n * Counts the number of similar sentence beginnings.\n *\n * @param {Array} sentenceBeginnings The array containing the first word of each sentence.\n * @param {Array} sentences The array containing all sentences.\n * @returns {Array} The array containing the objects containing the first words and the corresponding counts.\n */\nconst compareFirstWords = function(sentenceBeginnings, sentences) {\n const consecutiveFirstWords = [];\n let foundSentences = [];\n let sameBeginnings = 1;\n\n forEach(sentenceBeginnings, function(beginning, i) {\n const currentSentenceBeginning = beginning;\n const nextSentenceBeginning = sentenceBeginnings[i + 1];\n foundSentences.push(sentences[i]);\n\n if (startsWithSameWord(currentSentenceBeginning, nextSentenceBeginning)) {\n sameBeginnings++;\n } else {\n consecutiveFirstWords.push({\n word: currentSentenceBeginning,\n count: sameBeginnings,\n sentences: foundSentences\n });\n sameBeginnings = 1;\n foundSentences = [];\n }\n });\n\n return consecutiveFirstWords;\n};\n\n/**\n * Retrieves the first word from the sentence. If the first or second word is on an exception list of words that should not be considered as sentence\n * beginnings, the following word is also retrieved.\n *\n * @param {string} sentence The sentence to retrieve the first word from.\n * @param {Array} firstWordExceptions First word exceptions to match against.\n * @param {Array} secondWordExceptions Second word exceptions to match against.\n * @param {function} getWordsCustomHelper The language-specific helper function to retrieve words from text.\n *\n * @returns {string} The first word of the sentence.\n */\nfunction getSentenceBeginning(\n sentence,\n firstWordExceptions,\n secondWordExceptions,\n getWordsCustomHelper\n) {\n const stripped = stripTags(stripSpaces(sentence));\n let words = getWordsCustomHelper ? getWordsCustomHelper(stripped) : getWords(stripped);\n\n words = words.filter(word => /^\\p{L}/u.test(word));\n\n if (words.length === 0) {\n return '';\n }\n\n let firstWord = words[0].toLocaleLowerCase();\n\n if (firstWordExceptions.indexOf(firstWord) > -1 && words.length > 1) {\n firstWord = firstWord + ' ' + words[1];\n if (secondWordExceptions) {\n if (secondWordExceptions.includes(words[1])) {\n firstWord = firstWord + ' ' + words[2];\n }\n }\n }\n\n return firstWord;\n}\n\n/**\n * Gets the first word of each sentence from the text, and returns an object containing the first word of each sentence and the corresponding counts.\n *\n * @param {Paper} paper The Paper object to get the text from.\n * @param {Researcher} researcher The researcher this research is a part of.\n *\n * @returns {Object} The object containing the first word of each sentence and the corresponding counts.\n */\nexport default function(paper, researcher) {\n const firstWordExceptions = researcher.getConfig('firstWordExceptions');\n const secondWordExceptions = researcher.getConfig('secondWordExceptions');\n const getWordsCustomHelper = researcher.getHelper('getWordsCustomHelper');\n const memoizedTokenizer = researcher.getHelper('memoizedTokenizer');\n\n let text = paper.getText();\n text = removeHtmlBlocks(text);\n text = stripNonTextTags(text);\n text = filterShortcodesFromHTML(text, paper._attributes && paper._attributes.shortcodes);\n\n // Remove any HTML whitespace padding and replace it with a single whitespace.\n text = text.replace(/[\\s\\n]+/g, ' ');\n\n // Exclude text inside tables.\n text = text.replace(/<figure class='wp-block-table'>.*<\\/figure>/gs, '');\n\n let sentences = getSentences(text, memoizedTokenizer);\n\n const sentenceData = sentences.map(function(sentence) {\n const beginning = getSentenceBeginning(\n sentence,\n firstWordExceptions,\n secondWordExceptions,\n getWordsCustomHelper\n );\n\n return {sentence, beginning};\n });\n\n const filteredSentenceData = sentenceData.filter(function(item) {\n if (!item.beginning) return false;\n\n const stripped = stripTags(stripSpaces(item.sentence));\n const strippedNoSpaces = stripped.replace(/\\s+/g, '');\n const isDigitsOnly = strippedNoSpaces.length > 0 && /^[0-9]+$/.test(strippedNoSpaces);\n\n return !isDigitsOnly;\n });\n\n const filteredSentences = filteredSentenceData.map(item => item.sentence);\n const sentenceBeginnings = filteredSentenceData.map(item => item.beginning);\n\n return compareFirstWords(sentenceBeginnings, filteredSentences);\n}\n"],"mappings":"AAAA,OAAOA,QAAQ;AACf,OAAOC,YAAY;AACnB,OAAOC,WAAW;AAClB,SAAQC,aAAa,IAAIC,SAAS;AAElC,SAAQC,MAAM,EAAEC,OAAO,EAAEC,OAAO,QAAO,QAAQ;AAC/C,OAAOC,gBAAgB;AACvB,SAAQC,wBAAwB;AAChC,OAAOC,gBAAgB;;AAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG,SAAAA,CAASC,wBAAwB,EAAEC,qBAAqB,EAAE;EACnF,OAAO,CAACN,OAAO,CAACK,wBAAwB,CAAC,IAAIA,wBAAw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AAG,CAAC;;EAEpC;EACAJ,IAAI,GAAGA,IAAI,CAACI,OAAO,CAAC,+CAA+C,EAAE,EAAE,CAAC;EAExE,IAAI/B,SAAS,GAAGf,YAAY,CAAC0C,IAAI,EAAED,iBAAiB,CAAC;EAErD,MAAMM,YAAY,GAAGhC,SAAS,CAACiC,GAAG,CAAC,UAASvB,QAAQ,EAAE;IACpD,MAAMN,SAAS,GAAGK,oBAAoB,CACpCC,QAAQ,EACRC,mBAAmB,EACnBC,oBAAoB,EACpBC,oBACF,CAAC;IAED,OAAO;MAACH,QAAQ;MAAEN;IAAS,CAAC;EAC9B,CAAC,CAAC;EAEF,MAAM8B,oBAAoB,GAAGF,YAAY,CAAC3C,MAAM,CAAC,UAAS8C,IAAI,EAAE;IAC9D,IAAI,CAACA,IAAI,CAAC/B,SAAS,EAAE,OAAO,KAAK;IAEjC,MAAMU,QAAQ,GAAG1B,SAAS,CAACF,WAAW,CAACiD,IAAI,CAACzB,QAAQ,CAAC,CAAC;IACtD,MAAM0B,gBAAgB,GAAGtB,QAAQ,CAACiB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IACrD,MAAMM,YAAY,GAAGD,gBAAgB,CAACnB,MAAM,GAAG,CAAC,IAAI,UAAU,CAACD,IAAI,CAACoB,gBAAgB,CAAC;IAErF,OAAO,CAACC,YAAY;EACtB,CAAC,CAAC;EAEF,MAAMC,iBAAiB,GAAGJ,oBAAoB,CAACD,GAAG,CAACE,IAAI,IAAIA,IAAI,CAACzB,QAAQ,CAAC;EACzE,MAAMX,kBAAkB,GAAGmC,oBAAoB,CAACD,GAAG,CAACE,IAAI,IAAIA,IAAI,CAAC/B,SAAS,CAAC;EAE3E,OAAON,iBAAiB,CAACC,kBAAkB,EAAEuC,iBAAiB,CAAC;AACjE","ignoreList":[]}
|
|
@@ -2,6 +2,10 @@ import { merge } from 'lodash';
|
|
|
2
2
|
import Assessment from "../assessment";
|
|
3
3
|
import AssessmentResult from "../../../values/AssessmentResult";
|
|
4
4
|
import { IMAGES_IN_CONTENT_ID } from "../../../const/analysis";
|
|
5
|
+
const DEFAULT_TITLE = 'Images in content';
|
|
6
|
+
const DEFAULT_GOOD_TITLE = 'Images included';
|
|
7
|
+
const DEFAULT_GOOD_CONTENT = 'Images are included and well placed.';
|
|
8
|
+
const DEFAULT_BAD_CONTENT = 'This post is text heavy. Add images to break up sections and improve reading experience.';
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Represents the assessment that checks if the text has any images present.
|
|
@@ -22,12 +26,12 @@ export default class ImagesInContentAssessment extends Assessment {
|
|
|
22
26
|
ctaType: 'fix',
|
|
23
27
|
priority: 'high',
|
|
24
28
|
fixPosition: 'description',
|
|
25
|
-
title:
|
|
26
|
-
goodTitle:
|
|
29
|
+
title: DEFAULT_TITLE,
|
|
30
|
+
goodTitle: DEFAULT_GOOD_TITLE,
|
|
27
31
|
content: {
|
|
28
|
-
good:
|
|
32
|
+
good: DEFAULT_GOOD_CONTENT,
|
|
29
33
|
improve: '',
|
|
30
|
-
bad:
|
|
34
|
+
bad: DEFAULT_BAD_CONTENT
|
|
31
35
|
}
|
|
32
36
|
};
|
|
33
37
|
this.identifier = IMAGES_IN_CONTENT_ID;
|
|
@@ -79,7 +83,8 @@ export default class ImagesInContentAssessment extends Assessment {
|
|
|
79
83
|
status = 'good';
|
|
80
84
|
}
|
|
81
85
|
const score = this.getScore(this._config.priority, status);
|
|
82
|
-
const
|
|
86
|
+
const shouldUseTitleForGood = this._config.title !== DEFAULT_TITLE && this._config.goodTitle === DEFAULT_GOOD_TITLE;
|
|
87
|
+
const title = status === 'good' ? shouldUseTitleForGood ? this._config.title : this._config.goodTitle || this._config.title : this._config.title;
|
|
83
88
|
return {
|
|
84
89
|
score,
|
|
85
90
|
status,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImagesInContentAssessment.js","names":["merge","Assessment","AssessmentResult","IMAGES_IN_CONTENT_ID","ImagesInContentAssessment","constructor","config","defaultConfig","id","docUrl","ctaType","priority","fixPosition","title","goodTitle","content","good","improve","bad","identifier","_config","getResult","paper","researcher","imageCount","getResearch","assessmentResult","calculatedResult","calculateResult","setScore","score","setStatus","status","setTitle","isApplicable","hasText","getScore"],"sources":["../../../../../src/scoring/assessments/seo/ImagesInContentAssessment.js"],"sourcesContent":["import {merge} from 'lodash';\nimport Assessment from '../assessment';\nimport AssessmentResult from '../../../values/AssessmentResult';\nimport {IMAGES_IN_CONTENT_ID} from '@axyseo/const/analysis';\n\n/**\n * Represents the assessment that checks if the text has any images present.\n */\nexport default class ImagesInContentAssessment extends Assessment {\n /**\n * Sets the identifier and the config.\n *\n * @param {object} config The configuration to use.\n *\n * @returns {void}\n */\n constructor(config = {}) {\n super();\n\n const defaultConfig = {\n id: IMAGES_IN_CONTENT_ID,\n docUrl: 'https://docs.avada.io/seo-suite-help-center/seo-audit/on-page-seo/checklist',\n ctaType: 'fix',\n priority: 'high',\n fixPosition: 'description',\n title:
|
|
1
|
+
{"version":3,"file":"ImagesInContentAssessment.js","names":["merge","Assessment","AssessmentResult","IMAGES_IN_CONTENT_ID","DEFAULT_TITLE","DEFAULT_GOOD_TITLE","DEFAULT_GOOD_CONTENT","DEFAULT_BAD_CONTENT","ImagesInContentAssessment","constructor","config","defaultConfig","id","docUrl","ctaType","priority","fixPosition","title","goodTitle","content","good","improve","bad","identifier","_config","getResult","paper","researcher","imageCount","getResearch","assessmentResult","calculatedResult","calculateResult","setScore","score","setStatus","status","setTitle","isApplicable","hasText","getScore","shouldUseTitleForGood"],"sources":["../../../../../src/scoring/assessments/seo/ImagesInContentAssessment.js"],"sourcesContent":["import {merge} from 'lodash';\nimport Assessment from '../assessment';\nimport AssessmentResult from '../../../values/AssessmentResult';\nimport {IMAGES_IN_CONTENT_ID} from '@axyseo/const/analysis';\n\nconst DEFAULT_TITLE = 'Images in content';\nconst DEFAULT_GOOD_TITLE = 'Images included';\nconst DEFAULT_GOOD_CONTENT = 'Images are included and well placed.';\nconst DEFAULT_BAD_CONTENT =\n 'This post is text heavy. Add images to break up sections and improve reading experience.';\n\n/**\n * Represents the assessment that checks if the text has any images present.\n */\nexport default class ImagesInContentAssessment extends Assessment {\n /**\n * Sets the identifier and the config.\n *\n * @param {object} config The configuration to use.\n *\n * @returns {void}\n */\n constructor(config = {}) {\n super();\n\n const defaultConfig = {\n id: IMAGES_IN_CONTENT_ID,\n docUrl: 'https://docs.avada.io/seo-suite-help-center/seo-audit/on-page-seo/checklist',\n ctaType: 'fix',\n priority: 'high',\n fixPosition: 'description',\n title: DEFAULT_TITLE,\n goodTitle: DEFAULT_GOOD_TITLE,\n content: {\n good: DEFAULT_GOOD_CONTENT,\n improve: '',\n bad: DEFAULT_BAD_CONTENT\n }\n };\n\n this.identifier = IMAGES_IN_CONTENT_ID;\n this._config = merge(defaultConfig, config);\n }\n\n /**\n * Execute the Assessment and return a result.\n *\n * @param {Paper} paper The Paper object to assess.\n * @param {Researcher} researcher The Researcher object containing all available researches.\n * @returns {AssessmentResult} The result of the assessment, containing both a score and a descriptive text.\n */\n getResult({paper, researcher}) {\n this.imageCount = researcher.getResearch('imageCount');\n\n const assessmentResult = new AssessmentResult({config: this._config});\n\n const calculatedResult = this.calculateResult();\n\n assessmentResult.setScore(calculatedResult.score);\n assessmentResult.setStatus(calculatedResult.status);\n assessmentResult.setTitle(calculatedResult.title);\n\n return assessmentResult;\n }\n\n /**\n * Checks whether the paper has text.\n *\n * @param {Paper} paper The paper to use for the assessment.\n *\n * @returns {boolean} True when there is text.\n */\n isApplicable(paper) {\n return paper.hasText();\n }\n\n /**\n *\n * @returns {{score: number, status: string, title: string}}\n */\n calculateResult() {\n let status = '';\n\n if (!this.imageCount || this.imageCount === 0) {\n status = 'improve';\n } else {\n status = 'good';\n }\n\n const score = this.getScore(this._config.priority, status);\n const shouldUseTitleForGood =\n this._config.title !== DEFAULT_TITLE && this._config.goodTitle === DEFAULT_GOOD_TITLE;\n const title =\n status === 'good'\n ? shouldUseTitleForGood\n ? this._config.title\n : this._config.goodTitle || this._config.title\n : this._config.title;\n\n return {\n score,\n status,\n title\n };\n }\n}\n"],"mappings":"AAAA,SAAQA,KAAK,QAAO,QAAQ;AAC5B,OAAOC,UAAU;AACjB,OAAOC,gBAAgB;AACvB,SAAQC,oBAAoB;AAE5B,MAAMC,aAAa,GAAG,mBAAmB;AACzC,MAAMC,kBAAkB,GAAG,iBAAiB;AAC5C,MAAMC,oBAAoB,GAAG,sCAAsC;AACnE,MAAMC,mBAAmB,GACvB,0FAA0F;;AAE5F;AACA;AACA;AACA,eAAe,MAAMC,yBAAyB,SAASP,UAAU,CAAC;EAChE;AACF;AACA;AACA;AACA;AACA;AACA;EACEQ,WAAWA,CAACC,MAAM,GAAG,CAAC,CAAC,EAAE;IACvB,KAAK,CAAC,CAAC;IAEP,MAAMC,aAAa,GAAG;MACpBC,EAAE,EAAET,oBAAoB;MACxBU,MAAM,EAAE,6EAA6E;MACrFC,OAAO,EAAE,KAAK;MACdC,QAAQ,EAAE,MAAM;MAChBC,WAAW,EAAE,aAAa;MAC1BC,KAAK,EAAEb,aAAa;MACpBc,SAAS,EAAEb,kBAAkB;MAC7Bc,OAAO,EAAE;QACPC,IAAI,EAAEd,oBAAoB;QAC1Be,OAAO,EAAE,EAAE;QACXC,GAAG,EAAEf;MACP;IACF,CAAC;IAED,IAAI,CAACgB,UAAU,GAAGpB,oBAAoB;IACtC,IAAI,CAACqB,OAAO,GAAGxB,KAAK,CAACW,aAAa,EAAED,MAAM,CAAC;EAC7C;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEe,SAASA,CAAC;IAACC,KAAK;IAAEC;EAAU,CAAC,EAAE;IAC7B,IAAI,CAACC,UAAU,GAAGD,UAAU,CAACE,WAAW,CAAC,YAAY,CAAC;IAEtD,MAAMC,gBAAgB,GAAG,IAAI5B,gBAAgB,CAAC;MAACQ,MAAM,EAAE,IAAI,CAACc;IAAO,CAAC,CAAC;IAErE,MAAMO,gBAAgB,GAAG,IAAI,CAACC,eA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