You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improvement (v2): Allow authors to define a canonical URL to help with SEO #2603
Allowing users to define a canonical URL will greatly help with pointing search engines into the right direction, especially when multiple versions of the same doc item exist.
Pitch
As mentioned in the motivation, allowing users to define a canonical URL will greatly help with efforts regarding SEO. Not only will this ensure that search engines know what version of a particular doc item is most relevant, it will also ensure that other versions of the same doc item are known and are pointing to the most relevant / newest version. Also see https://yoast.com/rel-canonical/ for more information.
How this feature could work, is by adding an additional (optional) Markdown property that can defined in the header of the particular doc item. This property can then be used and outputted in the HTML as a <link rel="canonical" href="https://example.com/mydocitem/" />.
If this property is omitted from the header, it should still be outputted in the resulting HTML, but must point to itself.
It is possible to use custom SEO components directly inside a markdown file, thanks to MDX. It is not the best DX but is quite flexible in what it can do to override any meta we set by default.
# Markdown title
Some markdown text
import Head from '@docusaurus/Head';
<Head>
<title>My custom doc title</title><link rel="canonical" href="http://mysite.com/example" />
</Head>
The drawback is that you have to do this for all the docs you want to modify metadata (but that would be similar if we provided a frontmatter option anyway)
@slorber In my case, i'd like to add custom tags to some pages (excluding robots, for example).
I adopted the snippet you've posted, but I cannot get it working.
The MDX syntax is ok, the page is rendering, but the custom header tags don't appear at all.
Here is my markdown page:
---
title: About us
hide_table_of_contents: true
---
# About us
import Head from '@docusaurus/Head';
<Head>
<meta name="robots" content="noindex,nofollow,noarchive" />
</Head>
Further text is going here
I'm using the latest beta 70, versions 68/69 showed the same behavior.
It is possible to use custom SEO components directly inside a markdown file, thanks to MDX. It is not the best DX but is quite flexible in what it can do to override any meta we set by default.
# Markdown title
Some markdown text
import Head from '@docusaurus/Head';
<Head>
<title>My custom doc title</title>
<link rel="canonical" href="http://mysite.com/example" />
</Head>
The drawback is that you have to do this for all the docs you want to modify metadata (but that would be similar if we provided a frontmatter option anyway)
Do you think we can close this issue?
Hi @slorber, for some reason I'm only just not getting a notification that you responded.
Sadly, this would mean the doc maintainer (whom might not be the handiest when it comes to writing HTML/MDX), would need to be very aware of the proper syntax, would could easily lead to mistakes IMHO. Having a single property would indeed still mean the author needs to define it for every page that needs it customized, but only having to manipulate an option seems far less cumbersome, from a UX standpoint
@maxee you are right, it does not seem to work. Will add support for this.
@jcomack , I agree that first-class frontmatter support is simpler, but at the same time you have your usecase for canonical urls and other users have theirs for other metadata. First-class support means we'd end up with an infinite amount of frontmatter metadata we'd have to maintain in every single docusaurus plugin, cluttering the frontmatter API.
Each person can already implement its own doc renderer by swizzling the DocItem component, and adding the required metadata.
What if I made it so it was possible to write meta tags directly in the doc?
---title: About ushide_table_of_contents: true---
<metaname="robots"content="noindex,nofollow,noarchive" />
<linkrel="canonical"href="http://mysite.com/example" />
# About us
Further text is going here
What would be the ideal API that would solve all the head meta usecases?
For the canonical URL, I think it's common enough and we can make it an exception and add Yaml support, but still think it's a good idea to provide a generic solution to this problem.
Maybe just supporting link and meta arrays in frontmatter would be enough for a large quantity of usecases? Do you think of other head meta that would be interested to support?
What do you think of using Yaml arrays?
---title: About ushide_table_of_contents: truelink:
- rel: canonicalhref: http://mysite.com/examplemeta:
- name: robotscontent: noindex,nofollow,noarchive---# About us
Further text is going here
For the head meta-usecases, i like the idea with the YAML arrays. Fits perfect for meta-tags.
For all other use cases I think a generic solution like the one you described in your first answer (MDX) would be good.
If the MDX-solution would work, all further use cases would be covered.
However if realization of the MDX-solution is too complex I'd go for the YAML arrays for link-tags as well.
I'm adding support for using <head> in md files as a shortcut to the Docusaurus <Head> component in PR #5330
I prefer this solution based on <Head> because it is more flexible than yaml and cover various use-cases at once, including adding html/body attributes, and can even support evaluating the metadata at runtime thanks to MDX.
This will now work:
---id: my-doc-id---
<head>
<link rel="canonical" href="http://mysite.com/example" />
</head>
# Markdown title
Some markdown text
We may add frontmatter later: it can be useful if we support another parser than MDX, but in the end it will still remain based on <Head>, just the children would be created from the Yaml. But first I'd like to know if you feel limited with this approach.
Activity
slorber commentedon Oct 1, 2020
Hey,
It is possible to use custom SEO components directly inside a markdown file, thanks to MDX. It is not the best DX but is quite flexible in what it can do to override any meta we set by default.
The drawback is that you have to do this for all the docs you want to modify metadata (but that would be similar if we provided a frontmatter option anyway)
Do you think we can close this issue?
maxee commentedon Jan 11, 2021
@slorber In my case, i'd like to add custom tags to some pages (excluding robots, for example).
I adopted the snippet you've posted, but I cannot get it working.
The MDX syntax is ok, the page is rendering, but the custom header tags don't appear at all.
Here is my markdown page:
I'm using the latest beta 70, versions 68/69 showed the same behavior.
Is there anything I might have missed?
jcomack commentedon Jan 12, 2021
Hi @slorber, for some reason I'm only just not getting a notification that you responded.
Sadly, this would mean the doc maintainer (whom might not be the handiest when it comes to writing HTML/MDX), would need to be very aware of the proper syntax, would could easily lead to mistakes IMHO. Having a single property would indeed still mean the author needs to define it for every page that needs it customized, but only having to manipulate an option seems far less cumbersome, from a UX standpoint
slorber commentedon Jan 12, 2021
@maxee you are right, it does not seem to work. Will add support for this.
@jcomack , I agree that first-class frontmatter support is simpler, but at the same time you have your usecase for canonical urls and other users have theirs for other metadata. First-class support means we'd end up with an infinite amount of frontmatter metadata we'd have to maintain in every single docusaurus plugin, cluttering the frontmatter API.
Each person can already implement its own doc renderer by swizzling the
DocItemcomponent, and adding the required metadata.What if I made it so it was possible to write meta tags directly in the doc?
What would be the ideal API that would solve all the head meta usecases?
For the canonical URL, I think it's common enough and we can make it an exception and add Yaml support, but still think it's a good idea to provide a generic solution to this problem.
Maybe just supporting
linkandmetaarrays in frontmatter would be enough for a large quantity of usecases? Do you think of other head meta that would be interested to support?What do you think of using Yaml arrays?
maxee commentedon Jan 17, 2021
@slorber
For the head meta-usecases, i like the idea with the YAML arrays. Fits perfect for meta-tags.
For all other use cases I think a generic solution like the one you described in your first answer (MDX) would be good.
If the MDX-solution would work, all further use cases would be covered.
However if realization of the MDX-solution is too complex I'd go for the YAML arrays for link-tags as well.
a-parser commentedon May 18, 2021
Any updates on this issue? It's documented here: https://docusaurus.io/docs/docusaurus-core#head but totally doesn't work
slorber commentedon Aug 10, 2021
Hey
I'm adding support for using
<head>in md files as a shortcut to the Docusaurus<Head>component in PR #5330I prefer this solution based on
<Head>because it is more flexible than yaml and cover various use-cases at once, including adding html/body attributes, and can even support evaluating the metadata at runtime thanks to MDX.This will now work:
We may add frontmatter later: it can be useful if we support another parser than MDX, but in the end it will still remain based on
<Head>, just thechildrenwould be created from the Yaml. But first I'd like to know if you feel limited with this approach.