Skip to content

Commit d623e65

Browse files
committed
simplify metadata
1 parent 74a6251 commit d623e65

File tree

3 files changed

+56
-49
lines changed

3 files changed

+56
-49
lines changed

src/app/[[...markdownPath]]/page.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export default async function WrapperPage({
140140
}
141141
// Configure dynamic segments to be statically generated
142142
export const dynamicParams = false;
143+
143144
export async function generateMetadata({
144145
params,
145146
}: {
@@ -156,18 +157,16 @@ export async function generateMetadata({
156157
titleForTitleTag,
157158
} = await getPageContent(markdownPath).then(({meta}) => meta);
158159

159-
return {
160-
metadata: generateSeoMetadata({
161-
title,
162-
isHomePage: pathname === '/',
163-
path: pathname,
164-
description,
165-
titleForTitleTag,
166-
image: `/images/og-${section}.png`,
167-
searchOrder:
168-
section === 'learn' || (section === 'blog' && pathname !== '/blog')
169-
? order
170-
: undefined,
171-
}),
172-
};
160+
return generateSeoMetadata({
161+
title,
162+
isHomePage: pathname === '/',
163+
path: pathname,
164+
description,
165+
titleForTitleTag,
166+
image: `/images/og-${section}.png`,
167+
searchOrder:
168+
section === 'learn' || (section === 'blog' && pathname !== '/blog')
169+
? order
170+
: undefined,
171+
});
173172
}

src/app/layout.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {Suspense} from 'react';
1111
import {DevContentRefresher} from 'components/DevContentRefresher';
1212
import {ThemeScript} from 'components/ThemeScript';
1313
import {UwuScript} from 'components/UwuScript';
14+
import {Metadata} from 'next';
1415

1516
export const viewport = {
1617
themeColor: [
@@ -19,6 +20,43 @@ export const viewport = {
1920
],
2021
};
2122

23+
export const metadata: Metadata = {
24+
title: {default: 'React', template: '%s – React'},
25+
description:
26+
'React is the library for web and native user interfaces. Build user interfaces out of individual pieces called components written in JavaScript.',
27+
openGraph: {
28+
siteName: 'React',
29+
type: 'website',
30+
images: [{url: '/images/og-default.png'}],
31+
},
32+
twitter: {
33+
card: 'summary_large_image',
34+
site: '@reactjs',
35+
creator: '@reactjs',
36+
images: ['/images/og-default.png'],
37+
},
38+
verification: {
39+
google: 'sIlAGs48RulR4DdP95YSWNKZIEtCqQmRjzn-Zq-CcD0',
40+
},
41+
other: {
42+
'msapplication-TileColor': '#2b5797',
43+
'fb:app_id': '623268441017527',
44+
},
45+
icons: {
46+
icon: [
47+
{url: '/favicon-16x16.png', sizes: '16x16', type: 'image/png'},
48+
{url: '/favicon-32x32.png', sizes: '32x32', type: 'image/png'},
49+
],
50+
apple: [
51+
{url: '/apple-touch-icon.png', sizes: '180x180', type: 'image/png'},
52+
],
53+
other: [
54+
{rel: 'mask-icon', url: '/safari-pinned-tab.svg', color: '#404756'},
55+
],
56+
},
57+
manifest: '/site.webmanifest',
58+
};
59+
2260
function FontPreload() {
2361
return (
2462
<>

src/utils/generateMetadata.ts

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ function getDomain(languageCode: string): string {
1616
const subdomain = languageCode === 'en' ? '' : languageCode + '.';
1717
return subdomain + 'react.dev';
1818
}
19-
2019
export function generateMetadata({
2120
title,
2221
titleForTitleTag,
23-
image = '/images/og-default.png',
22+
image,
2423
isHomePage,
2524
description: customDescription,
2625
searchOrder,
@@ -29,14 +28,12 @@ export function generateMetadata({
2928
const siteDomain = getDomain(siteConfig.languageCode);
3029
const canonicalUrl = `https://${siteDomain}${path.split(/[\?\#]/)[0]}`;
3130

32-
// Allow setting a different title for Google results
3331
const pageTitle =
3432
(titleForTitleTag ?? title) + (isHomePage ? '' : ' – React');
35-
// Twitter's meta parser is not very good.
3633
const twitterTitle = pageTitle.replace(/[<>]/g, '');
3734

3835
const description = isHomePage
39-
? 'React is the library for web and native user interfaces. Build user interfaces out of individual pieces called components written in JavaScript. React is designed to let you seamlessly combine components written by independent people, teams, and organizations.'
36+
? 'React is the library for web and native user interfaces...'
4037
: customDescription ?? 'The library for web and native user interfaces';
4138

4239
const alternateLanguages = {
@@ -49,7 +46,7 @@ export function generateMetadata({
4946
),
5047
};
5148

52-
const metadata: Metadata = {
49+
return {
5350
title: pageTitle,
5451
description: isHomePage ? description : undefined,
5552
alternates: {
@@ -60,46 +57,19 @@ export function generateMetadata({
6057
title: pageTitle,
6158
description,
6259
url: canonicalUrl,
63-
siteName: 'React',
64-
type: 'website',
6560
images: [
66-
{
67-
url: `https://${siteDomain}${image}`,
68-
},
61+
{url: `https://${siteDomain}${image || '/images/og-default.png'}`},
6962
],
7063
},
7164
twitter: {
72-
card: 'summary_large_image',
73-
site: '@reactjs',
74-
creator: '@reactjs',
7565
title: twitterTitle,
7666
description,
77-
images: [`https://${siteDomain}${image}`],
78-
},
79-
verification: {
80-
google: 'sIlAGs48RulR4DdP95YSWNKZIEtCqQmRjzn-Zq-CcD0',
67+
images: [`https://${siteDomain}${image || '/images/og-default.png'}`],
8168
},
8269
other: {
83-
'msapplication-TileColor': '#2b5797',
84-
'fb:app_id': '623268441017527',
8570
...(searchOrder != null && {
8671
'algolia-search-order': searchOrder.toString(),
8772
}),
8873
},
89-
icons: {
90-
icon: [
91-
{url: '/favicon-16x16.png', sizes: '16x16', type: 'image/png'},
92-
{url: '/favicon-32x32.png', sizes: '32x32', type: 'image/png'},
93-
],
94-
apple: [
95-
{url: '/apple-touch-icon.png', sizes: '180x180', type: 'image/png'},
96-
],
97-
other: [
98-
{rel: 'mask-icon', url: '/safari-pinned-tab.svg', color: '#404756'},
99-
],
100-
},
101-
manifest: '/site.webmanifest',
10274
};
103-
104-
return metadata;
10575
}

0 commit comments

Comments
 (0)