Skip to content

Commit 55e866f

Browse files
committed
feat: update pages meta & og image
1 parent e76f576 commit 55e866f

File tree

11 files changed

+72
-2
lines changed

11 files changed

+72
-2
lines changed

apps/docs/src/app/(home)/blog/[slug]/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ export async function generateMetadata(props: {
4747
const page = blog.getPage([params.slug]);
4848

4949
if (!page) notFound();
50+
const url = page.url;
5051

5152
return createMetadata({
5253
title: page.data.title,
5354
description: page.data.description,
55+
pathname: url,
56+
image: page.data.image,
5457
});
5558
}
5659

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { createMetadata } from '@/lib/metadata';
12
import { blog } from '@/lib/source';
3+
import { getTranslations } from 'next-intl/server';
24
import Link from 'next/link';
35

46
export default function Page(): React.ReactElement {
@@ -41,3 +43,11 @@ export default function Page(): React.ReactElement {
4143
</main>
4244
);
4345
}
46+
47+
export async function generateMetadata() {
48+
const t = await getTranslations('baseOptions');
49+
return createMetadata({
50+
title: t('blog'),
51+
pathname: '/blog',
52+
});
53+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { getLearnTabs } from '@/lib/learn';
2+
import { createMetadata } from '@/lib/metadata';
23
import { useTranslations } from 'next-intl';
4+
import { getTranslations } from 'next-intl/server';
35
import Link from 'next/link';
46

57
export default function LearnIndexPage() {
@@ -38,3 +40,12 @@ export default function LearnIndexPage() {
3840
</main>
3941
);
4042
}
43+
44+
export async function generateMetadata() {
45+
const t = await getTranslations('baseOptions');
46+
return createMetadata({
47+
title: t('learn'),
48+
pathname: '/learn',
49+
image: 'https://nextjs.org/learn/opengraph-image-r39hrb.jpg',
50+
});
51+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { createMetadata } from '@/lib/metadata';
12
import { useTranslations } from 'next-intl';
3+
import { getTranslations } from 'next-intl/server';
24
import Link from 'next/link';
35

46
export default function HomePage() {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ export async function generateMetadata(props: {
124124
if (!page) notFound();
125125

126126
return createMetadata({
127-
title: page.data.nav_title || page.data.title,
127+
title: page.data.title,
128128
description: page.data.description,
129+
pathname: page.url,
130+
image: `https://nextjs.org/api/docs-og?title=${page.data.title}`,
129131
});
130132
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ export async function generateMetadata(props: {
5555
return createMetadata({
5656
title: page.data.headline || page.data.title,
5757
description: page.data.description,
58+
pathname: page.url,
59+
image: page.data.image,
5860
});
5961
}

apps/docs/src/lib/metadata.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
import { SITES } from '@next-i18n/const';
12
import type { Metadata } from 'next/types';
23

3-
export function createMetadata(override: Metadata): Metadata {
4+
export function createMetadata(
5+
override: Metadata & { pathname?: string; image?: string },
6+
): Metadata {
47
return {
58
...override,
69
openGraph: {
710
title: override.title ?? undefined,
811
description: override.description ?? undefined,
912
images: '/twitter-card.png',
1013
siteName: 'nextjs.im',
14+
...(override.image
15+
? {
16+
images: override.image,
17+
}
18+
: {}),
1119
...override.openGraph,
1220
},
1321
twitter: {
@@ -16,8 +24,25 @@ export function createMetadata(override: Metadata): Metadata {
1624
title: override.title ?? undefined,
1725
description: override.description ?? undefined,
1826
images: '/twitter-card.png',
27+
...(override.image
28+
? {
29+
images: override.image,
30+
}
31+
: {}),
1932
...override.twitter,
2033
},
34+
...(override.pathname
35+
? {
36+
alternates: {
37+
canonical: baseUrl.origin + override.pathname,
38+
languages: {
39+
'en-US': SITES.en + override.pathname,
40+
'zh-Hans': SITES['zh-hans'] + override.pathname,
41+
'zh-Hant': SITES['zh-hant'] + override.pathname,
42+
},
43+
},
44+
}
45+
: {}),
2146
};
2247
}
2348

packages/const/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
},
2222
"publishConfig": {
2323
"access": "public"
24+
},
25+
"dependencies": {
26+
"next-intl": "^4.1.0"
2427
}
2528
}

packages/const/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './language';
2+
export * from './sites';

packages/const/src/sites.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Locale } from 'next-intl';
2+
3+
export const SITES: Record<Locale, string> = {
4+
en: 'https://en.nextjs.im',
5+
'zh-hans': 'https://zh-hans.nextjs.im',
6+
'zh-hant': 'https://zh-hant.nextjs.im',
7+
};

0 commit comments

Comments
 (0)