Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(seo): support spanish in link-text audit #7547

Merged
merged 2 commits into from
Apr 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lighthouse-core/audits/seo/link-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ const BLOCKLIST = new Set([
'続きを読む',
'続く',
'全文表示',
// Spanish
'click aquí',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a fair amount of duplication with the permutations, I wonder if we could do some replacements to keep the signal in here high?

could be as simple as an easy map for now

const CHARACTER_REPLACEMENTS = new Map([
  [/í/g, 'i'],
  [/á/g, 'a'],
  [/ó/g, 'o'],
])

function normalizeText(text) {
  let normalized = text.trim().toLowerCase();
  for (const [regex, replacement] of CHARACTER_REPLACEMENTS.entries()) {
     normalized = normalized.replace(regex, replacement)
  }

  return normalized;
}
...

return BLOCKLIST.has(normalizeText(link.text));

DISCLAIMER: untested

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could do some replacements to keep the signal in here high?

ha, the problem is with this change I would wonder if normalizeText is quite correct or if it's missing something or adding things I'm not expecting, versus just scanning a medium sized list :)

But I'd be ok with tests for it 👍

'click aqui',
'clicka aquí',
'clicka aqui',
'pincha aquí',
'pincha aqui',
'aquí',
'aqui',
'más',
'mas',
'más información',
'más informacion',
'mas información',
'mas informacion',
'este',
'enlace',
'este enlace',
'empezar',
]);
const i18n = require('../../lib/i18n/i18n.js');

Expand Down