Skip to content

Commit f4808fc

Browse files
committed
feat: update meta
1 parent 74a348f commit f4808fc

File tree

9 files changed

+78
-23
lines changed

9 files changed

+78
-23
lines changed

apps/docs/messages/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"title": "Next.js",
44
"doc": "Documentation"
55
},
6+
"meta": {
7+
"title": "Next.js - English",
8+
"description": "Production grade React applications that scale. The world's leading companies use Next.js by Vercel to build static and dynamic websites and web applications."
9+
},
610
"sidebar": {
711
"app": {
812
"title": "Using App Router",

apps/docs/messages/zh-hans.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"title": "Next.js 简体中文",
44
"doc": "文档"
55
},
6+
"meta": {
7+
"title": "Next.js - 简体中文",
8+
"description": "生产级 React 应用,具备卓越扩展能力。全球领先企业都在用 Next.js by Vercel 构建静态和动态网站及 Web 应用。"
9+
},
610
"sidebar": {
711
"app": {
812
"title": "使用 App 路由器",

apps/docs/public/twitter-card.png

582 KB
Loading

apps/docs/src/app/(home)/page.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useTranslations } from 'next-intl';
2-
import { getTranslations } from 'next-intl/server';
32
import Link from 'next/link';
43

54
export default function HomePage() {
@@ -88,10 +87,3 @@ export default function HomePage() {
8887
</main>
8988
);
9089
}
91-
92-
export async function generateMetadata() {
93-
const t = await getTranslations('HomePage');
94-
return {
95-
title: t('title'),
96-
};
97-
}

apps/docs/src/app/docs/[[...slug]]/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DocsLayout } from '@/components/layout';
2+
import { createMetadata } from '@/lib/metadata';
23
import { getPage } from '@/lib/page';
34
import { getPageTreePeers } from '@/lib/pageTree';
45
import { type Page, type Source, source } from '@/lib/source';
@@ -128,8 +129,8 @@ export async function generateMetadata(props: {
128129
const page = getPage(url);
129130
if (!page) notFound();
130131

131-
return {
132+
return createMetadata({
132133
title: page.data.nav_title || page.data.title,
133134
description: page.data.description,
134-
};
135+
});
135136
}

apps/docs/src/app/favicon.ico

14.7 KB
Binary file not shown.

apps/docs/src/app/layout.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,42 @@ import { NextIntlClientProvider, hasLocale } from 'next-intl';
22
import './global.css';
33
import { Provider } from '@/app/provider';
44

5-
import { getLocale } from 'next-intl/server';
6-
import { Inter } from 'next/font/google';
5+
import { getLocale, getTranslations } from 'next-intl/server';
76

8-
const inter = Inter({
7+
import { baseUrl, createMetadata } from '@/lib/metadata';
8+
import type { Viewport } from 'next';
9+
import { Geist, Geist_Mono } from 'next/font/google';
10+
11+
export async function generateMetadata() {
12+
const t = await getTranslations('meta');
13+
14+
return createMetadata({
15+
title: {
16+
template: `%s | ${t('title')}`,
17+
default: t('title'),
18+
},
19+
description: t('description'),
20+
metadataBase: baseUrl,
21+
});
22+
}
23+
24+
const geist = Geist({
25+
variable: '--font-sans',
926
subsets: ['latin'],
1027
});
1128

29+
const mono = Geist_Mono({
30+
variable: '--font-mono',
31+
subsets: ['latin'],
32+
});
33+
34+
export const viewport: Viewport = {
35+
themeColor: [
36+
{ media: '(prefers-color-scheme: dark)', color: '#0A0A0A' },
37+
{ media: '(prefers-color-scheme: light)', color: '#fff' },
38+
],
39+
};
40+
1241
export default async function Layout({
1342
children,
1443
}: {
@@ -17,7 +46,11 @@ export default async function Layout({
1746
const locale = await getLocale();
1847

1948
return (
20-
<html lang={locale} className={inter.className} suppressHydrationWarning>
49+
<html
50+
lang={locale}
51+
className={`${geist.variable} ${mono.variable}`}
52+
suppressHydrationWarning
53+
>
2154
<body className="flex flex-col min-h-screen">
2255
<NextIntlClientProvider>
2356
<Provider>{children}</Provider>

apps/docs/src/hooks/useLayoutOptions.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
22
import { Book } from 'lucide-react';
33
import { useTranslations } from 'next-intl';
4+
import Image from 'next/image';
45

56
export const useBaseOptions = () => {
67
const t = useTranslations('baseOptions');
78
return {
89
nav: {
910
title: (
1011
<>
11-
<svg
12-
width="24"
13-
height="24"
14-
xmlns="http://www.w3.org/2000/svg"
15-
aria-label="Logo"
16-
>
17-
<title>Logo</title>
18-
<circle cx={12} cy={12} r={12} fill="currentColor" />
19-
</svg>
12+
<Image src="/favicon.ico" alt="logo" width={24} height={24} />
2013
{t('title')}
2114
</>
2215
),

apps/docs/src/lib/metadata.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { Metadata } from 'next/types';
2+
3+
export function createMetadata(override: Metadata): Metadata {
4+
return {
5+
...override,
6+
openGraph: {
7+
title: override.title ?? undefined,
8+
description: override.description ?? undefined,
9+
url: baseUrl,
10+
images: '/twitter-card.png',
11+
siteName: 'nextjs.im',
12+
...override.openGraph,
13+
},
14+
twitter: {
15+
card: 'summary_large_image',
16+
creator: '@xiaoyu2er',
17+
title: override.title ?? undefined,
18+
description: override.description ?? undefined,
19+
images: '/twitter-card.png',
20+
...override.twitter,
21+
},
22+
};
23+
}
24+
25+
export const baseUrl =
26+
process.env.NODE_ENV === 'development' || !process.env.VERCEL_URL
27+
? new URL('http://localhost:3000')
28+
: new URL(`https://${process.env.VERCEL_URL}`);

0 commit comments

Comments
 (0)