mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 04:12:34 +00:00
Try to fix Google titles for directive pages (#6393)
https://twitter.com/sophiebits/status/1718042539650150609
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
title: "'use client'"
|
||||
titleForTitleTag: "'use client' directive"
|
||||
canary: true
|
||||
---
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
title: "'use server'"
|
||||
titleForTitleTag: "'use server' directive"
|
||||
canary: true
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user