Skip to content

new_audit(canonical): document has a valid rel=canonical#4163

Merged
paulirish merged 14 commits intoGoogleChrome:masterfrom
kdzwinel:seo-canonical
Jan 10, 2018
Merged

new_audit(canonical): document has a valid rel=canonical#4163
paulirish merged 14 commits intoGoogleChrome:masterfrom
kdzwinel:seo-canonical

Conversation

@kdzwinel
Copy link
Collaborator

@kdzwinel kdzwinel commented Jan 3, 2018

Closes #3178

Success:
screen shot 2018-01-03 at 01 31 40

Failure:
screen shot 2018-01-03 at 01 47 11

if (HEADER_SAFELIST.has(headerName.toLowerCase())) {
headers[headerName] = headerValue;
headers[headerName] = headers[headerName] || [];
headers[headerName].push(headerValue);
Copy link
Collaborator Author

@kdzwinel kdzwinel Jan 3, 2018

Choose a reason for hiding this comment

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

Some headers can appear multiple times in the HTTP response (set-cookie, link, etc.) and, in such cases, {name:[value1, value2]} is a format expected by response.writeHead.

canonicalURL.pathname === '/' && baseURL.pathname !== '/') {
return {
rawValue: false,
displayValue: 'points to a root of the same origin',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rviscomi I made these displayValues very short and while this works for invalid URL all others require more explanation. Not sure if displayValue is the right place for this explanation though (limited formatting, not much space) - maybe separate documentation page that we discussed would help here?

Copy link
Member

Choose a reason for hiding this comment

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

Can the failureDescription be overwritten to have failure-specific explanations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From what I tested neither failureDescription nor helpText can be overwritten ☹️ We only have displayValue and details. Unfortunately, details do not support any formatting when it comes to text:

screen shot 2018-01-03 at 02 52 37

Copy link
Member

Choose a reason for hiding this comment

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

Is the immutability of failureDescription a bug or a feature? cc @paulirish

failureDescription: 'Links do not have descriptive text',
helpText: 'Descriptive link text helps search engines understand your content. ' +
'[Learn more](https://webmasters.googleblog.com/2008/10/importance-of-link-architecture.html)',
'[Learn more](https://webmasters.googleblog.com/2008/10/importance-of-link-architecture.html).',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unrelated change, sorry to shove it here, but it was killing me

had_to_fix_it

Copy link
Member

Choose a reason for hiding this comment

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

😄 👍

@@ -0,0 +1,166 @@
/**
* @license Copyright 2017 Google Inc. All Rights Reserved.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@paulirish you always check those 😉 so here is a fun riddle - I created this file in 2017, but it will be merged into master in 2018. Should I put 2017 or 2018 here?

Copy link
Member

Choose a reason for hiding this comment

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

2017 sgtm. :)

canonicalURL.pathname === '/' && baseURL.pathname !== '/') {
return {
rawValue: false,
displayValue: 'points to a root of the same origin',
Copy link
Member

Choose a reason for hiding this comment

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

Can the failureDescription be overwritten to have failure-specific explanations?

failureDescription: 'Links do not have descriptive text',
helpText: 'Descriptive link text helps search engines understand your content. ' +
'[Learn more](https://webmasters.googleblog.com/2008/10/importance-of-link-architecture.html)',
'[Learn more](https://webmasters.googleblog.com/2008/10/importance-of-link-architecture.html).',
Copy link
Member

Choose a reason for hiding this comment

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

😄 👍

@@ -0,0 +1,166 @@
/**
* @license Copyright 2017 Google Inc. All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

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

🎊

2018?


if (canonicals.length === 0) {
return {
rawValue: true,
Copy link
Member

Choose a reason for hiding this comment

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

when 4052 lands, we'll want to add notApplicable: true to this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added it right away (it doesn't really matter if this PR will be merge after or before #4052)

@kdzwinel
Copy link
Collaborator Author

kdzwinel commented Jan 4, 2018

@patrickhulce we talked with @rviscomi about your idea to split this audit into two (errors with weight 1 and warnings with weight 0). On the one hand, it'd allow us to have separate titles and descriptions for both audits and provide more explanation, but on the other hand, it would create a confusing situation where user gets 100/100 but still sees that one of the audits is failing. So, if you don't have any strong feelings regarding the split we'd like to avoid it.

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

this looks a-ok to me! 👌

there's probably a nicer looking way we can handle the displayValue issue in the future but doesn't make sense to block on it 👍

over to @paulirish for any closing thoughts

};
}

// another common mistake is to have canonical pointing from all pages of the website to its root
Copy link
Collaborator

Choose a reason for hiding this comment

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

still somewhat 😢 that this can fail for intentional usage. though I don't have a real life example so it's probably fine :)


it('fails when canonical points to the root while current URL is not the root', () => {
const mainResource = {
url: 'https://example.com/articles/cats-and-you',
Copy link
Collaborator

Choose a reason for hiding this comment

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

😆

baseURL.href !== canonicalURL.href) {
return {
rawValue: false,
displayValue: `points to another hreflang location (${baseURL.href})`,
Copy link
Member

@paulirish paulirish Jan 10, 2018

Choose a reason for hiding this comment

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

Rather than overloading displayValue I think we should abuse debugString like we already do for the PWA ones.

We can even extend https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/audits/multi-check-audit.js much like the splash screen one.

This also sorts out the mutable failureDescription concern above.

(yes, debugString is supposed to be exceptions, not details of failing tests. But since the PWA audits are already violating that, we might as well violate it here, too.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TIL about the multi-check-audit! Looks cool, but it probably makes most sense for audits returning multiple failures (Failures: ${result.failures.join(', ')}.) and this one doesn't, so I'll just switch displayValues to debugStrings.

@kdzwinel
Copy link
Collaborator Author

@paulirish thank you for taking a look at this! I addressed your debugString comment:

screen shot 2018-01-11 at 00 32 18

@paulirish paulirish merged commit 2ba8d1f into GoogleChrome:master Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants