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

feat(v2): add canonical URL to <head> #2694

Merged
merged 1 commit into from
May 13, 2020

Conversation

jcomack
Copy link
Contributor

@jcomack jcomack commented Apr 29, 2020

Motivation

Currently Docusaurus does not support canonical URLs. From a search engine standpoint, a canonical URL is an important piece of information and can help direct them to the correct content.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  • Visit any static page or doc page
  • View source, search for <link rel="canonical" href="<URL of the page you're currently viewing>" />

Related PRs

This PR is a good first step to further implement #2603, as it introduces a good default value.

@jcomack jcomack requested a review from lex111 as a code owner April 29, 2020 13:44
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 29, 2020
@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit 2c63e05

https://deploy-preview-2694--docusaurus-2.netlify.app

Copy link
Contributor

@lex111 lex111 left a comment

Choose a reason for hiding this comment

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

@jcomack hmm, I wonder what the canonical URL should be if some hosting providers automatically (like Netlify) add trailing slashes by default?

For example, https://deploy-preview-2694--docusaurus-2.netlify.app/docs/introduction -> https://deploy-preview-2694--docusaurus-2.netlify.app/docs/introduction/ but canonical URL without trailing slash, it is OK?

image

<link data-react-helmet="true" rel="canonical" href="https://v2.docusaurus.io/docs/introduction">

@jonoalderson
Copy link

jonoalderson commented Apr 30, 2020

@jcomack hmm, I wonder what the canonical URL should be if some hosting providers automatically (like Netlify) add trailing slashes by default?

Yes, that'll cause problems. Some nuance here, as:

  • In those cases, the og:url tag will already be incorrect (as it'll not feature the trailing slash).
  • The trailing slash should really be appended automatically, universally, rather than relying on hosting rules.
  • The og:url and other tags should be updated to match that.

@lex111
Copy link
Contributor

lex111 commented Apr 30, 2020

So let's add trailing slash to permalink.

@jonoalderson
Copy link

So let's add trailing slash to permalink.

That'd be great, if we could! :)

@jcomack
Copy link
Contributor Author

jcomack commented May 11, 2020

Just curious about the status regarding this situation. Any updates? :)

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

Seems legit. Should we add to the blog too?

@yangshun yangshun added the pr: new feature This PR adds a new API or behavior. label May 13, 2020
@yangshun yangshun changed the title feat: add canonical URL to head section feat(v2): add canonical URL to <head> May 13, 2020
@yangshun yangshun merged commit aac4e27 into facebook:master May 13, 2020
@lex111
Copy link
Contributor

lex111 commented May 13, 2020

We still needed to add trailing slash to permalink, didn't we?

@jonoalderson
Copy link

Yep! :)

@yangshun
Copy link
Contributor

yangshun commented May 13, 2020

They have the same contents, why do we need the trailing slash? Google indexes both version of webpages similarly. The important thing here is to have the canonical tag, rather than not.

Yes, duplicate content is bad. If you have www.example.com/blog-post/ and www.example.com/blog-post both at the same time, Google will see two identical blog posts at two different URLs on your site. This is bad, and if it’s done throughout your entire site, it’s doubly bad. That much duplicate content is a penalty for sure.

However, if you always tell Google that the URL with the trailing slash should be canonicalized to the one without the trailing slash, they now understand that the one without the slash is the intended version, and the one with the slash exists just to give access to the page to anyone landing on it without a redirect.

Source: https://www.seoblog.com/remove-trailing-slash-urls/

@jonoalderson
Copy link

There are inconsistencies between the canonical URL value, the og:url, and the value(s) users/agents can request a page via. These should all be consistent.

@yangshun
Copy link
Contributor

Hmm ok let's add the trailing slash then.

@jcomack jcomack deleted the introduce-canonical-url branch May 14, 2020 11:22
@lex111 lex111 added this to the v2.0.0-alpha.55 milestone May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants