diff options
| author | Denis Ledoux <dle@odoo.com> | 2015-05-28 15:13:01 +0200 |
|---|---|---|
| committer | Denis Ledoux <dle@odoo.com> | 2015-05-28 15:15:53 +0200 |
| commit | 9fe059027ebcc3f9c86f8cedb9c6d8a25e8b5e3a (patch) | |
| tree | a61051cc03835354da1aa266c490e697a4c339f0 /addons/website/static/src/js/website.seo.js | |
| parent | 970f9466aa795e86d913371b7a712543d7481f81 (diff) | |
[FIX] website: seo, auto detection of keywords with accents in boundaries
Javascript regex \b is not unicode aware,
and words beginning or ending by accents won't match \b
We therefore use a custom regex to replace \b.
Basically, it's a regex matching all words separators
such as dot, comma, spaces, etc. and other unicode
separators as well.
opw-641005
Diffstat (limited to 'addons/website/static/src/js/website.seo.js')
| -rw-r--r-- | addons/website/static/src/js/website.seo.js | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/addons/website/static/src/js/website.seo.js b/addons/website/static/src/js/website.seo.js index 7e32a780bf1..4592a6e90d5 100644 --- a/addons/website/static/src/js/website.seo.js +++ b/addons/website/static/src/js/website.seo.js @@ -6,6 +6,10 @@ website.seo = {}; + // This replaces \b, because accents(e.g. à, é) are not seen as word boundaries. + // Javascript \b is not unicode aware, and words beginning or ending by accents won't match \b + var WORD_SEPARATORS_REGEX = '([\\u2000-\\u206F\\u2E00-\\u2E7F\'!"#\\$%&\\(\\)\\*\\+,\\-\\.\\/:;<=>\\?¿¡@\\[\\]\\^_`\\{\\|\\}~\\s]+|^|$)'; + function analyzeKeyword(htmlPage, keyword) { return htmlPage.isInTitle(keyword) ? { title: 'label label-primary', @@ -293,13 +297,13 @@ return $('body').children().not('.js_seo_configuration').text(); }, isInBody: function (text) { - return new RegExp("\\b"+text+"\\b", "gi").test(this.bodyText()); + return new RegExp(WORD_SEPARATORS_REGEX+text+WORD_SEPARATORS_REGEX, "gi").test(this.bodyText()); }, isInTitle: function (text) { - return new RegExp("\\b"+text+"\\b", "gi").test(this.title()); + return new RegExp(WORD_SEPARATORS_REGEX+text+WORD_SEPARATORS_REGEX, "gi").test(this.title()); }, isInDescription: function (text) { - return new RegExp("\\b"+text+"\\b", "gi").test(this.description()); + return new RegExp(WORD_SEPARATORS_REGEX+text+WORD_SEPARATORS_REGEX, "gi").test(this.description()); }, }); |
