axyseo 2.1.3 → 2.1.4
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.
|
@@ -32,6 +32,9 @@ const getTextFullPage = data => {
|
|
|
32
32
|
const bodyString = html?.length > 0 ? html.replace(/<\/?[^>]+(>|$)/g, ' ') : '';
|
|
33
33
|
return [faqString, data.title, bodyString, data?.metafields_avadaSEO_after_content, data.metafields_global_title_tag, data.metafields_global_description_tag].join(' ').toLowerCase();
|
|
34
34
|
};
|
|
35
|
+
const escapeRegExp = string => {
|
|
36
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
37
|
+
};
|
|
35
38
|
|
|
36
39
|
/**
|
|
37
40
|
*
|
|
@@ -51,7 +54,8 @@ const countWordsInRelatedKeywords = ({
|
|
|
51
54
|
text
|
|
52
55
|
}) => {
|
|
53
56
|
const keyword = text.toLocaleLowerCase();
|
|
54
|
-
const
|
|
57
|
+
const escapedKeyword = escapeRegExp(keyword);
|
|
58
|
+
const regex = new RegExp(`(?:^|\\W)${escapedKeyword}(?:\\W|$)`, 'gu');
|
|
55
59
|
const length = (string.match(regex) || []).length;
|
|
56
60
|
const percentage = parseFloat((length / total * 100).toFixed(1));
|
|
57
61
|
if (!isWordUsedExceeding) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkRelatedKeywords.js","names":["paper","researcher","data","getData","related_keywords","transformRelatedKeyword","string","getTextFullPage","countWordsInRelatedKeywords","keywords","map","keyword","text","faqString","faqs","status","questions","i","question","answer","join","html","body_html","descriptionHtml","bodyString","length","replace","title","metafields_avadaSEO_after_content","metafields_global_title_tag","metafields_global_description_tag","toLowerCase","total","split","filter","word","words","totalWordUsed","isWordUsedExceeding","forEach","toLocaleLowerCase","regex","RegExp","match","percentage","parseFloat","toFixed"],"sources":["../../../src/languageProcessing/researches/checkRelatedKeywords.js"],"sourcesContent":["/**\n * Checks how many sentences from a text contain at least one transition word or two-part transition word\n * that are defined in the transition words config and two part transition words config.\n *\n * @param {Paper} paper The Paper object to get text from.\n * @param {Researcher} researcher The researcher.\n *\n * @returns {object} An object with the total number of sentences in the text\n * and the total number of sentences containing one or more transition words.\n */\nexport default function(paper, researcher) {\n const data = paper.getData();\n const related_keywords = transformRelatedKeyword(data?.related_keywords || []);\n const string = getTextFullPage(data);\n return countWordsInRelatedKeywords({related_keywords, string});\n}\n\nexport const transformRelatedKeyword = keywords =>\n keywords.map(keyword => (typeof keyword === 'string' ? {text: keyword} : keyword)) || [];\n\n/**\n *\n * @param data\n * @returns {string}\n */\nconst getTextFullPage = data => {\n const faqString = data.faqs.status\n ? data.faqs.questions.map(i => i.question + ' ' + i.answer).join(' ')\n : '';\n const html = data.body_html || data.descriptionHtml;\n const bodyString = html?.length > 0 ? html.replace(/<\\/?[^>]+(>|$)/g, ' ') : '';\n return [\n faqString,\n data.title,\n bodyString,\n data?.metafields_avadaSEO_after_content,\n data.metafields_global_title_tag,\n data.metafields_global_description_tag\n ]\n .join(' ')\n .toLowerCase();\n};\n\n/**\n *\n * @param related_keywords\n * @param string\n * @returns {{totalWordUsed: number, words: {}, isWordUsedExceeding: boolean}}\n */\nconst countWordsInRelatedKeywords = ({related_keywords, string}) => {\n const total = string.split(/\\s+/).filter(word => word.length > 0).length;\n const words = {};\n let totalWordUsed = 0;\n let isWordUsedExceeding = false;\n\n related_keywords.forEach(({text}) => {\n const keyword = text.toLocaleLowerCase();\n
|
|
1
|
+
{"version":3,"file":"checkRelatedKeywords.js","names":["paper","researcher","data","getData","related_keywords","transformRelatedKeyword","string","getTextFullPage","countWordsInRelatedKeywords","keywords","map","keyword","text","faqString","faqs","status","questions","i","question","answer","join","html","body_html","descriptionHtml","bodyString","length","replace","title","metafields_avadaSEO_after_content","metafields_global_title_tag","metafields_global_description_tag","toLowerCase","escapeRegExp","total","split","filter","word","words","totalWordUsed","isWordUsedExceeding","forEach","toLocaleLowerCase","escapedKeyword","regex","RegExp","match","percentage","parseFloat","toFixed"],"sources":["../../../src/languageProcessing/researches/checkRelatedKeywords.js"],"sourcesContent":["/**\n * Checks how many sentences from a text contain at least one transition word or two-part transition word\n * that are defined in the transition words config and two part transition words config.\n *\n * @param {Paper} paper The Paper object to get text from.\n * @param {Researcher} researcher The researcher.\n *\n * @returns {object} An object with the total number of sentences in the text\n * and the total number of sentences containing one or more transition words.\n */\nexport default function(paper, researcher) {\n const data = paper.getData();\n const related_keywords = transformRelatedKeyword(data?.related_keywords || []);\n const string = getTextFullPage(data);\n return countWordsInRelatedKeywords({related_keywords, string});\n}\n\nexport const transformRelatedKeyword = keywords =>\n keywords.map(keyword => (typeof keyword === 'string' ? {text: keyword} : keyword)) || [];\n\n/**\n *\n * @param data\n * @returns {string}\n */\nconst getTextFullPage = data => {\n const faqString = data.faqs.status\n ? data.faqs.questions.map(i => i.question + ' ' + i.answer).join(' ')\n : '';\n const html = data.body_html || data.descriptionHtml;\n const bodyString = html?.length > 0 ? html.replace(/<\\/?[^>]+(>|$)/g, ' ') : '';\n return [\n faqString,\n data.title,\n bodyString,\n data?.metafields_avadaSEO_after_content,\n data.metafields_global_title_tag,\n data.metafields_global_description_tag\n ]\n .join(' ')\n .toLowerCase();\n};\n\nconst escapeRegExp = string => {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n};\n\n/**\n *\n * @param related_keywords\n * @param string\n * @returns {{totalWordUsed: number, words: {}, isWordUsedExceeding: boolean}}\n */\nconst countWordsInRelatedKeywords = ({related_keywords, string}) => {\n const total = string.split(/\\s+/).filter(word => word.length > 0).length;\n const words = {};\n let totalWordUsed = 0;\n let isWordUsedExceeding = false;\n\n related_keywords.forEach(({text}) => {\n const keyword = text.toLocaleLowerCase();\n const escapedKeyword = escapeRegExp(keyword);\n const regex = new RegExp(`(?:^|\\\\W)${escapedKeyword}(?:\\\\W|$)`, 'gu');\n const length = (string.match(regex) || []).length;\n\n const percentage = parseFloat(((length / total) * 100).toFixed(1));\n if (!isWordUsedExceeding) {\n isWordUsedExceeding = percentage > 1;\n }\n totalWordUsed += length;\n words[text] = {length, percentage};\n });\n\n return {totalWordUsed, words, isWordUsedExceeding};\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,UAASA,KAAK,EAAEC,UAAU,EAAE;EACzC,MAAMC,IAAI,GAAGF,KAAK,CAACG,OAAO,CAAC,CAAC;EAC5B,MAAMC,gBAAgB,GAAGC,uBAAuB,CAACH,IAAI,EAAEE,gBAAgB,IAAI,EAAE,CAAC;EAC9E,MAAME,MAAM,GAAGC,eAAe,CAACL,IAAI,CAAC;EACpC,OAAOM,2BAA2B,CAAC;IAACJ,gBAAgB;IAAEE;EAAM,CAAC,CAAC;AAChE;AAEA,OAAO,MAAMD,uBAAuB,GAAGI,QAAQ,IAC7CA,QAAQ,CAACC,GAAG,CAACC,OAAO,IAAK,OAAOA,OAAO,KAAK,QAAQ,GAAG;EAACC,IAAI,EAAED;AAAO,CAAC,GAAGA,OAAQ,CAAC,IAAI,EAAE;;AAE1F;AACA;AACA;AACA;AACA;AACA,MAAMJ,eAAe,GAAGL,IAAI,IAAI;EAC9B,MAAMW,SAAS,GAAGX,IAAI,CAACY,IAAI,CAACC,MAAM,GAC9Bb,IAAI,CAACY,IAAI,CAACE,SAAS,CAACN,GAAG,CAACO,CAAC,IAAIA,CAAC,CAACC,QAAQ,GAAG,GAAG,GAAGD,CAAC,CAACE,MAAM,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,GACnE,EAAE;EACN,MAAMC,IAAI,GAAGnB,IAAI,CAACoB,SAAS,IAAIpB,IAAI,CAACqB,eAAe;EACnD,MAAMC,UAAU,GAAGH,IAAI,EAAEI,MAAM,GAAG,CAAC,GAAGJ,IAAI,CAACK,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,GAAG,EAAE;EAC/E,OAAO,CACLb,SAAS,EACTX,IAAI,CAACyB,KAAK,EACVH,UAAU,EACVtB,IAAI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