Repository navigation
I noticed that for docs I can set both a frontMatter title: property (that goes to SEO) and a H1 text title that is shown as the page title.
For blog posts the behaviour is different, the frontMatter title: property goes both to SEO and is displayed as the page title; if present, a H1 is ignored.
Is this (inconsistent) behaviour intended?
In my case, the problem is that the <meta ... title ...> obtained from the frontMatter title: concatenated with the site title, results in a pretty long string, that is not only redundant, but the SEO validators complain that the page title is longer than 60.
For example:
<meta data-rh="true" property="og:title"
content="xPack GNU AArch64 Embedded GCC v12.3.1-2.1 released | xPack GNU AArch64 Embedded GCC">
Should I worry about the SEO limit? If so, is there a solution to adjust the code that generates the meta lines to make them shorter? (for docs I fixed them with a shorter frontMatter title:, but for blog posts this solution does not work).
All reactions
For blog posts, we don't allow # title because this would enable Markdown/JSX in it, while we need the title to be a pure string that we can use on other places such as the paginated list, the sidebar, the RSS feed entries... It's a technical constraint we currently have although we might try to solve it later.
You can put <head><title>My SEO title</title></head> in any MDX file to override the default meta SEO title.
Replies: 5 comments 13 replies
For blog posts, we don't allow # title because this would enable Markdown/JSX in it, while we need the title to be a pure string that we can use on other places such as the paginated list, the sidebar, the RSS feed entries... It's a technical constraint we currently have although we might try to solve it later.
You can put <head><title>My SEO title</title></head> in any MDX file to override the default meta SEO title.
All reactions
For blog posts, we don't allow # title because this would enable Markdown/JSX in it, while we need the title to be a pure string that we can use on other places such as the paginated list, the sidebar, the RSS feed entries...
That makes sense.
It's a technical constraint we currently have although we might try to solve it later.
I'm not aware of the internals, and JSX in the title might be tough, but I guess markdown formatting can be stripped out. Should I open an issue to keep track of this?
You can put <title>My SEO title</title> in any MDX file to override the default meta SEO title.
That was helpful.
I added <head><title>{frontMatter.title}</title></head> as the first line of the post, and the <head><title> shortened to:
<title data-rh="true">xPack GNU AArch64 Embedded GCC v13.3.1-1.1 released</title>
But the <meta ... og:title ...> is unchanged:
<meta data-rh="true" property="og:title"
content="xPack GNU AArch64 Embedded GCC v13.3.1-1.1 released | xPack GNU AArch64 Embedded GCC">
Is this acceptable?
All reactions
What you put in head is what you get, you can also put any other <meta> tag as documented.
It's not publicly documented but we have a theme-common React helper component.
You can create your own and use it in MDX too.
<PageMetadata title={title} /> export function PageMetadata({ title, description, keywords, image, children, }: PageMetadataProps): JSX.Element { const pageTitle = useTitleFormatter(title); const {withBaseUrl} = useBaseUrlUtils(); const pageImage = image ? withBaseUrl(image, {absolute: true}) : undefined; return ( <Head> {title && <title>{pageTitle}</title>} {title && <meta property="og:title" content={pageTitle} />} {description && <meta name="description" content={description} />} {description && <meta property="og:description" content={description} />} {keywords && ( <meta name="keywords" content={ // https://github.com/microsoft/TypeScript/issues/17002 (Array.isArray(keywords) ? keywords.join(',') : keywords) as string } /> )} {pageImage && <meta property="og:image" content={pageImage} />} {pageImage && <meta name="twitter:image" content={pageImage} />} {children} </Head> ); }
All reactions
I think we already support Markdown title for blog posts, but it's a best effort and the stringification does not support all Markdown/JSX constructs
CleanShot 2024年10月11日 at 15 09 03
I remember we added support to ignore inline code blocks in #4882
You can create an issue if you want, it's a known limitation we have on the blog.
Unlike docs that is able to support both MDX content title (rendered) and frontMatter.title (SEO metadata), we only have one title for the blog:
const title = frontMatter.title ?? contentTitle ?? parsedBlogFileName.text;
This is because the MDX doc is not rendered "as is". When there's a # ContentTitle, we have to extract it as string and then render it separately, because we have to include extra metadata in between:
CleanShot 2024年10月11日 at 15 17 00
Maybe that's possible to solve, but I'm not sure how (maybe with a Remark plugin 🤷♂️ )
All reactions
PageMetadata ... You can create your own and use it in MDX too.
How do I tell Docusaurus about it? Do I have to swizzle something? Add it to the config.ts?
const title = frontMatter.title ?? contentTitle ?? parsedBlogFileName.text;
This explains why in my case the # Title was ignored, the frontMatter.title took precedence.
This is because the MDX doc is not rendered "as is". When there's a # ContentTitle, we have to extract it as string and then render it separately, because we have to include extra metadata in between:
I see.
However I think that a consistent behaviour with docs would be less confusing. In my use case this means the # Title to be used as title for both docs and posts, and the frontMatter.title to be used for the SEO in both cases.
All reactions
How do I tell Docusaurus about it? Do I have to swizzle something? Add it to the config.ts?
You can import (or provide it with MDXComponents) any component you want in MDX, including ours, yours, and our <Head> component directly.
import {PageMetadata} from '@docusaurus/theme-common';
However I think that a consistent behaviour with docs would be less confusing. In my use case this means the # Title to be used as title for both docs and posts, and the frontMatter.title to be used for the SEO in both cases.
Yes, that would be better although not sure how to handle it.
All reactions
If the SEO definitions for title and description require some size limits, don't you think that it would be nice for Docusaurus to check them during build time and possibly issue warnings?
All reactions
I don't think there's a size limit, it's just a recommendation.
A 65char title here and there is IMHO perfectly fine and I wouldn't like to pollute the Docusaurus logs just for that.
It's not the responsibility of Docusaurus to emit such SEO warnings. There are dedicated SEO tools such as Ahrefs, SEMrush and many others that can monitor your site and advise you.
All reactions
SEO tools such as Ahrefs, SEMrush ...
For the record, these tools are not free.
All reactions
I personally use Ahefs for free on my website and Docusaurus website. Free plans are limited but are still doing much more than warning about a 60char title limit.
There are probably free oss tools you can use.
The point is, validating SEO is not related to static site generation, it can and should be plugged from the outside.
All reactions
I did some experimentation and decided on a workaround, but it does not cover the Home page and I consider it quite kludgy.
I added two <head> lines to each post and documentation page:
<head><title>{frontMatter.title}</title></head>
<head><meta property="og:title" content={frontMatter.title}/></head>
Basically this is to avoid appending the suffix | Site Title to all pages.
This was not exactly easy, given that the site is actually a collection of 20+ sites, with more than 500 pages. The solution required some sed & awk magic.
However, I did not find a workaround for the Home page; I could not add a <head><title>...</title></head> via headTags, because the title is not an attribute, but an element content.
Any suggestion how to customise the Home page title (actually to remove the site title suffix)?
I saw that you have a configuration option to configure the separator used in the title (to a dino!). I think an even more useful configuration option would be to completely disable the suffix.
All reactions
You don't need to add twice the <head> tag, this also works and is similar to what you'd use in a regular HTML page.
<head> <title>{frontMatter.title}</title></head> <meta property="og:title" content={frontMatter.title}/> </head>
But again if you setup the MDX component, you could just write <PageMetadata title={title}/> or <MyCustomHelper title={title}/>
This was not exactly easy, given that the site is actually a collection of 20+ sites, with more than 500 pages. The solution required some sed & awk magic.
For Markdown you can write a remark plugin that does it automatically for you by adding extra <head> tags automatically.
You can also use the preprocessor option. Although it's not really the recommended solution you might find it simpler in practice.
However, I did not find a workaround for the Home page;
It's the same: https://docusaurus.io/docs/docusaurus-core#head
<head> in md is just a shortcut to <Head> in React.
In both cases you can override the title, or any other meta, to what you want.
I saw that you have a configuration option to configure the separator used in the title (to a dino!). I think an even more useful configuration option would be to completely disable the suffix.
Agree this titleDelimiter thing is quite annoying and we should change this.
see also issue #5878
Our lib has a concept of titleTemplate, and I think we should use that instead of our current logic: https://github.com/nfl/react-helmet
All reactions
I think that now I have an acceptable solution. In case someone has the same problem, here is a recap:
Docs
I have a set of 20+ documentation webs, for related projects, all generated from the same template. Since sometimes I work with more of them in parallel, I found it necessary to have the project name explicitly mentioned in the documentation pages, for example How to install the xPack GNU Arm Embedded GCC, instead of Install Guide, as the menu & sidebar items read.
Using the default Docusaurus logic, the resulting SEO title is How to install the xPack GNU Arm Embedded GCC | xPack GNU Arm Embedded GCC, which is long and redundant.
Since docs allow both frontMatter title and H1 headers, I defined the frontMatter title: Install Guide, and # How to install the xPack GNU Arm Embedded GCC.
With this configuration the page title is the long explicit string and the SEO title was shortened to Install Guide | xPack GNU Arm Embedded GCC.
Posts
The blog posts are mainly used to announce releases, and the titles look like xPack GNU AArch64 Embedded GCC v13.3.1-1.1 released, which is the desired string to be displayed in the page, in the Archive, in atom/rss, etc.
Using the default Docusaurus logic, the resulting SEO title is xPack GNU AArch64 Embedded GCC v13.3.1-1.1 released | xPack GNU Arm Embedded GCC, which is way too long and redundant.
Since for posts currently it is not possible to define separate frontMatter titles and H1 headers, the solution was to add a custom frontMatter seo_title: Version 13.3.1-1.1 released, and a <PageMetadata title={frontMatter.seo_title} /> in the post body (after the <!-- truncate --> line, otherwise it applies to the Archive pages too).
With this configuration the page title is the long explicit string and the SEO title was shortened to Version 13.3.1-1.1 released | xPack GNU Arm Embedded GCC.
I could not find instructions in the Docusaurus web site how to provide it with MDXComponents, so I imported it in each blog post.
The top web site is:
It would be really nice for Docusaurus to support both frontMatter titles and H1 headers for blog posts, it would make these use cases simpler.
All reactions
Note: technically you don't even have to modify your source docs. You could swizzle BlogPostItem and use Head or <PageMetadata> here.
Even better, you could swizzle BlogPostPageMetadata and change our default theme logic. This tweak might be enough:
All reactions
It would be really nice for Docusaurus to support both frontMatter titles and H1 headers for blog posts, it would make these use cases simpler.
I think we could add a new title_meta front matter as a temporary workaround until we are able to solve this problem in a better way. Do you want to submit a PR?
All reactions
Do you want to submit a PR?
I'll try to take a look at the code, perhaps there is a better way than adding temporary workarounds.
All reactions
Here is a first proposal:
All reactions
The suggestion to introduce a dedicated SEO title field in blog front matter seems like a practical improvement. Developers should not have to compromise between a descriptive article heading and a concise SEO title. Abnaasi supports flexible content management solutions that make technical optimization easier.