File tree Expand file tree Collapse file tree 11 files changed +72
-2
lines changed Expand file tree Collapse file tree 11 files changed +72
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1+ import { createMetadata } from '@/lib/metadata' ;
12import { blog } from '@/lib/source' ;
3+ import { getTranslations } from 'next-intl/server' ;
24import Link from 'next/link' ;
35
46export 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+ }
Original file line number Diff line number Diff line change 11import { getLearnTabs } from '@/lib/learn' ;
2+ import { createMetadata } from '@/lib/metadata' ;
23import { useTranslations } from 'next-intl' ;
4+ import { getTranslations } from 'next-intl/server' ;
35import Link from 'next/link' ;
46
57export 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+ }
Original file line number Diff line number Diff line change 1+ import { createMetadata } from '@/lib/metadata' ;
12import { useTranslations } from 'next-intl' ;
3+ import { getTranslations } from 'next-intl/server' ;
24import Link from 'next/link' ;
35
46export default function HomePage ( ) {
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 1+ import { SITES } from '@next-i18n/const' ;
12import 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
Original file line number Diff line number Diff line change 2121 },
2222 "publishConfig" : {
2323 "access" : " public"
24+ },
25+ "dependencies" : {
26+ "next-intl" : " ^4.1.0"
2427 }
2528}
Original file line number Diff line number Diff line change 11export * from './language' ;
2+ export * from './sites' ;
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments