Unverified Commit 75831c08 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[metadata]: add pinterest meta tag (#76988)

### What
Adds support for Pinterest's Rich Pin Data meta tag, while
future-proofing for additional Pinterest tags.

This currently works like so

```js
pinterest: {
  richPin: true
}
  ```
 And would resolve to:
 
```html
 <meta property="pinterest-rich-pin" content="true" />
 ```

x-ref: https://help.pinterest.com/en/business/article/rich-pins

Closes #70873

---------
Co-authored-by: 's avatarDominik Koch <dominik@koch-bautechnik.de>
parent 808934a5
...@@ -48,6 +48,7 @@ export function createDefaultMetadata(): ResolvedMetadata { ...@@ -48,6 +48,7 @@ export function createDefaultMetadata(): ResolvedMetadata {
formatDetection: null, formatDetection: null,
itunes: null, itunes: null,
facebook: null, facebook: null,
pinterest: null,
abstract: null, abstract: null,
appLinks: null, appLinks: null,
archives: null, archives: null,
......
...@@ -157,6 +157,18 @@ export function FacebookMeta({ ...@@ -157,6 +157,18 @@ export function FacebookMeta({
]) ])
} }
export function PinterestMeta({
pinterest,
}: {
pinterest: ResolvedMetadata['pinterest']
}) {
if (!pinterest || !pinterest.richPin) return null
const { richPin } = pinterest
return <meta property="pinterest-rich-pin" content={richPin.toString()} />
}
const formatDetectionKeys = [ const formatDetectionKeys = [
'telephone', 'telephone',
'date', 'date',
......
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
ViewportMeta, ViewportMeta,
VerificationMeta, VerificationMeta,
FacebookMeta, FacebookMeta,
PinterestMeta,
} from './generate/basic' } from './generate/basic'
import { AlternatesMetadata } from './generate/alternate' import { AlternatesMetadata } from './generate/alternate'
import { import {
...@@ -392,6 +393,7 @@ function createMetadataElements(metadata: ResolvedMetadata) { ...@@ -392,6 +393,7 @@ function createMetadataElements(metadata: ResolvedMetadata) {
AlternatesMetadata({ alternates: metadata.alternates }), AlternatesMetadata({ alternates: metadata.alternates }),
ItunesMeta({ itunes: metadata.itunes }), ItunesMeta({ itunes: metadata.itunes }),
FacebookMeta({ facebook: metadata.facebook }), FacebookMeta({ facebook: metadata.facebook }),
PinterestMeta({ pinterest: metadata.pinterest }),
FormatDetectionMeta({ formatDetection: metadata.formatDetection }), FormatDetectionMeta({ formatDetection: metadata.formatDetection }),
VerificationMeta({ verification: metadata.verification }), VerificationMeta({ verification: metadata.verification }),
AppleWebAppMeta({ appleWebApp: metadata.appleWebApp }), AppleWebAppMeta({ appleWebApp: metadata.appleWebApp }),
......
...@@ -215,7 +215,6 @@ function mergeMetadata({ ...@@ -215,7 +215,6 @@ function mergeMetadata({
case 'facebook': case 'facebook':
target.facebook = resolveFacebook(source.facebook) target.facebook = resolveFacebook(source.facebook)
break break
case 'verification': case 'verification':
target.verification = resolveVerification(source.verification) target.verification = resolveVerification(source.verification)
break break
...@@ -272,6 +271,7 @@ function mergeMetadata({ ...@@ -272,6 +271,7 @@ function mergeMetadata({
case 'referrer': case 'referrer':
case 'formatDetection': case 'formatDetection':
case 'manifest': case 'manifest':
case 'pinterest':
// @ts-ignore TODO: support inferring // @ts-ignore TODO: support inferring
target[key] = source[key] || null target[key] = source[key] || null
break break
......
...@@ -106,6 +106,15 @@ export type ResolvedFacebook = { ...@@ -106,6 +106,15 @@ export type ResolvedFacebook = {
admins?: string[] | undefined admins?: string[] | undefined
} }
export type Pinterest = PinterestRichPin
export type PinterestRichPin = {
richPin: string | boolean
}
export type ResolvedPinterest = {
richPin?: string
}
// Format Detection // Format Detection
// This is a poorly specified metadata export type that is supposed to // This is a poorly specified metadata export type that is supposed to
// control whether the device attempts to conver text that matches // control whether the device attempts to conver text that matches
......
...@@ -23,9 +23,11 @@ import type { ...@@ -23,9 +23,11 @@ import type {
Facebook, Facebook,
FormatDetection, FormatDetection,
ItunesApp, ItunesApp,
Pinterest,
ResolvedAppleWebApp, ResolvedAppleWebApp,
ResolvedAppLinks, ResolvedAppLinks,
ResolvedFacebook, ResolvedFacebook,
ResolvedPinterest,
ViewportLayout, ViewportLayout,
} from './extra-types' } from './extra-types'
import type { import type {
...@@ -369,6 +371,17 @@ interface Metadata extends DeprecatedMetadataFields { ...@@ -369,6 +371,17 @@ interface Metadata extends DeprecatedMetadataFields {
*/ */
facebook?: null | Facebook | undefined facebook?: null | Facebook | undefined
/**
* The Pinterest metadata for the document to choose whether opt out of rich pin data.
*
* @example
* ```tsx
* pinterest: { richPin: true }
* // Renders <meta name="pinterest-rich-pin" content="true" />
* ```
*/
pinterest?: null | Pinterest
/** /**
* The common verification tokens for the document. * The common verification tokens for the document.
* *
...@@ -606,6 +619,8 @@ interface ResolvedMetadata extends DeprecatedMetadataFields { ...@@ -606,6 +619,8 @@ interface ResolvedMetadata extends DeprecatedMetadataFields {
facebook: null | ResolvedFacebook facebook: null | ResolvedFacebook
pinterest: null | ResolvedPinterest
// common verification tokens // common verification tokens
verification: null | ResolvedVerification verification: null | ResolvedVerification
......
...@@ -8,6 +8,9 @@ export async function generateMetadata() { ...@@ -8,6 +8,9 @@ export async function generateMetadata() {
appId: '12345678', appId: '12345678',
admins: ['120', '122', '124'], admins: ['120', '122', '124'],
}, },
pinterest: {
richPin: true,
},
} }
return metadata return metadata
} }
...@@ -162,13 +162,14 @@ describe('app dir - metadata', () => { ...@@ -162,13 +162,14 @@ describe('app dir - metadata', () => {
) )
}) })
it('should support facebook related tags', async () => { it('should support socials related tags like facebook and pinterest', async () => {
const browser = await next.browser('/facebook') const browser = await next.browser('/socials')
const matchMultiDom = createMultiDomMatcher(browser) const matchMultiDom = createMultiDomMatcher(browser)
await matchMultiDom('meta', 'property', 'content', { await matchMultiDom('meta', 'property', 'content', {
'fb:app_id': '12345678', 'fb:app_id': '12345678',
'fb:admins': ['120', '122', '124'], 'fb:admins': ['120', '122', '124'],
'pinterest-rich-pin': 'true',
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment