Try to fix Google titles for directive pages (#6393)

https://twitter.com/sophiebits/status/1718042539650150609
This commit is contained in:
Sophie Alpert
2023-10-27 19:48:24 -07:00
committed by GitHub
parent b8acf016dc
commit 4bdb87b172
4 changed files with 14 additions and 2 deletions

View File

@@ -28,7 +28,12 @@ interface PageProps {
children: React.ReactNode;
toc: Array<TocItem>;
routeTree: RouteItem;
meta: {title?: string; canary?: boolean; description?: string};
meta: {
title?: string;
titleForTitleTag?: string;
canary?: boolean;
description?: string;
};
section: 'learn' | 'reference' | 'community' | 'blog' | 'home' | 'unknown';
}
@@ -107,6 +112,7 @@ export function Page({children, toc, routeTree, meta, section}: PageProps) {
<>
<Seo
title={title}
titleForTitleTag={meta.titleForTitleTag}
isHomePage={isHomePage}
image={`/images/og-` + section + '.png'}
searchOrder={searchOrder}

View File

@@ -9,6 +9,7 @@ import {siteConfig} from '../siteConfig';
export interface SeoProps {
title: string;
titleForTitleTag: undefined | string;
description?: string;
image?: string;
// jsonld?: JsonLDType | Array<JsonLDType>;
@@ -36,6 +37,7 @@ function getDomain(languageCode: string): string {
export const Seo = withRouter(
({
title,
titleForTitleTag,
image = '/images/og-default.png',
router,
children,
@@ -46,7 +48,9 @@ export const Seo = withRouter(
const canonicalUrl = `https://${siteDomain}${
router.asPath.split(/[\?\#]/)[0]
}`;
const pageTitle = isHomePage ? title : title + ' React';
// Allow setting a different title for Google results
const pageTitle =
(titleForTitleTag ?? title) + (isHomePage ? '' : ' React');
// Twitter's meta parser is not very good.
const twitterTitle = pageTitle.replace(/[<>]/g, '');
let description = isHomePage

View File

@@ -1,5 +1,6 @@
---
title: "'use client'"
titleForTitleTag: "'use client' directive"
canary: true
---

View File

@@ -1,5 +1,6 @@
---
title: "'use server'"
titleForTitleTag: "'use server' directive"
canary: true
---