-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for metadata (#44729)
This PR implements page and layout exported `metadata` field support with limited properties. ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [x] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) Co-authored-by: Jiachi Liu <[email protected]> Co-authored-by: Tim Neutkens <[email protected]>
- Loading branch information
1 parent
55f3a6d
commit d1f6a42
Showing
37 changed files
with
2,317 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { ResolvedMetadata } from './types/metadata-interface' | ||
|
||
export const createDefaultMetadata = (): ResolvedMetadata => { | ||
return { | ||
viewport: 'width=device-width, initial-scale=1', | ||
|
||
// Other values are all null | ||
metadataBase: null, | ||
title: null, | ||
description: null, | ||
applicationName: null, | ||
authors: null, | ||
generator: null, | ||
keywords: null, | ||
referrer: null, | ||
themeColor: null, | ||
colorScheme: null, | ||
creator: null, | ||
publisher: null, | ||
robots: null, | ||
alternates: { | ||
canonical: null, | ||
languages: {}, | ||
}, | ||
icons: null, | ||
openGraph: null, | ||
twitter: null, | ||
verification: {}, | ||
appleWebApp: null, | ||
formatDetection: null, | ||
itunes: null, | ||
abstract: null, | ||
appLinks: null, | ||
archives: null, | ||
assets: null, | ||
bookmarks: null, | ||
category: null, | ||
classification: null, | ||
other: {}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { ResolvedMetadata } from '../types/metadata-interface' | ||
|
||
import React from 'react' | ||
|
||
export function ResolvedAlternatesMetadata({ | ||
metadata, | ||
}: { | ||
metadata: ResolvedMetadata | ||
}) { | ||
return ( | ||
<> | ||
{metadata.alternates.canonical ? ( | ||
<link rel="canonical" href={metadata.alternates.canonical.toString()} /> | ||
) : null} | ||
{Object.entries(metadata.alternates.languages).map(([locale, url]) => | ||
url ? ( | ||
<link | ||
key={locale} | ||
rel="alternate" | ||
hrefLang={locale} | ||
href={url.toString()} | ||
/> | ||
) : null | ||
)} | ||
{metadata.alternates.media | ||
? Object.entries(metadata.alternates.media).map(([media, url]) => | ||
url ? ( | ||
<link | ||
key={media} | ||
rel="alternate" | ||
media={media} | ||
href={url.toString()} | ||
/> | ||
) : null | ||
) | ||
: null} | ||
{metadata.alternates.types | ||
? Object.entries(metadata.alternates.types).map(([type, url]) => | ||
url ? ( | ||
<link | ||
key={type} | ||
rel="alternate" | ||
type={type} | ||
href={url.toString()} | ||
/> | ||
) : null | ||
) | ||
: null} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { ResolvedMetadata } from '../types/metadata-interface' | ||
|
||
import React from 'react' | ||
import { Meta } from './utils' | ||
|
||
export function ResolvedBasicMetadata({ | ||
metadata, | ||
}: { | ||
metadata: ResolvedMetadata | ||
}) { | ||
return ( | ||
<> | ||
<meta charSet="utf-8" /> | ||
{metadata.title !== null ? ( | ||
<title>{metadata.title.absolute}</title> | ||
) : null} | ||
<Meta name="description" content={metadata.description} /> | ||
<Meta name="application-name" content={metadata.applicationName} /> | ||
<Meta name="author" content={metadata.authors?.join(',')} /> | ||
<Meta name="generator" content={metadata.generator} /> | ||
<Meta name="keywords" content={metadata.keywords?.join(',')} /> | ||
<Meta name="referrer" content={metadata.referrer} /> | ||
<Meta name="theme-color" content={metadata.themeColor} /> | ||
<Meta name="color-scheme" content={metadata.colorScheme} /> | ||
<Meta name="viewport" content={metadata.viewport} /> | ||
<Meta name="creator" content={metadata.creator} /> | ||
<Meta name="publisher" content={metadata.publisher} /> | ||
<Meta name="robots" content={metadata.robots} /> | ||
<Meta name="abstract" content={metadata.abstract} /> | ||
{metadata.archives | ||
? metadata.archives.map((archive) => ( | ||
<link rel="archives" href={archive} key={archive} /> | ||
)) | ||
: null} | ||
{metadata.assets | ||
? metadata.assets.map((asset) => ( | ||
<link rel="assets" href={asset} key={asset} /> | ||
)) | ||
: null} | ||
{metadata.bookmarks | ||
? metadata.bookmarks.map((bookmark) => ( | ||
<link rel="bookmarks" href={bookmark} key={bookmark} /> | ||
)) | ||
: null} | ||
<Meta name="category" content={metadata.category} /> | ||
<Meta name="classification" content={metadata.classification} /> | ||
{Object.entries(metadata.other).map(([name, content]) => ( | ||
<Meta | ||
key={name} | ||
name={name} | ||
content={Array.isArray(content) ? content.join(',') : content} | ||
/> | ||
))} | ||
</> | ||
) | ||
} |
Oops, something went wrong.