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 {
formatDetection: null,
itunes: null,
facebook: null,
pinterest: null,
abstract: null,
appLinks: null,
archives: null,
......
......@@ -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 = [
'telephone',
'date',
......
......@@ -12,6 +12,7 @@ import {
ViewportMeta,
VerificationMeta,
FacebookMeta,
PinterestMeta,
} from './generate/basic'
import { AlternatesMetadata } from './generate/alternate'
import {
......@@ -392,6 +393,7 @@ function createMetadataElements(metadata: ResolvedMetadata) {
AlternatesMetadata({ alternates: metadata.alternates }),
ItunesMeta({ itunes: metadata.itunes }),
FacebookMeta({ facebook: metadata.facebook }),
PinterestMeta({ pinterest: metadata.pinterest }),
FormatDetectionMeta({ formatDetection: metadata.formatDetection }),
VerificationMeta({ verification: metadata.verification }),
AppleWebAppMeta({ appleWebApp: metadata.appleWebApp }),
......
......@@ -215,7 +215,6 @@ function mergeMetadata({
case 'facebook':
target.facebook = resolveFacebook(source.facebook)
break
case 'verification':
target.verification = resolveVerification(source.verification)
break
......@@ -272,6 +271,7 @@ function mergeMetadata({
case 'referrer':
case 'formatDetection':
case 'manifest':
case 'pinterest':
// @ts-ignore TODO: support inferring
target[key] = source[key] || null
break
......
......@@ -106,6 +106,15 @@ export type ResolvedFacebook = {
admins?: string[] | undefined
}
export type Pinterest = PinterestRichPin
export type PinterestRichPin = {
richPin: string | boolean
}
export type ResolvedPinterest = {
richPin?: string
}
// Format Detection
// This is a poorly specified metadata export type that is supposed to
// control whether the device attempts to conver text that matches
......
......@@ -23,9 +23,11 @@ import type {
Facebook,
FormatDetection,
ItunesApp,
Pinterest,
ResolvedAppleWebApp,
ResolvedAppLinks,
ResolvedFacebook,
ResolvedPinterest,
ViewportLayout,
} from './extra-types'
import type {
......@@ -369,6 +371,17 @@ interface Metadata extends DeprecatedMetadataFields {
*/
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.
*
......@@ -606,6 +619,8 @@ interface ResolvedMetadata extends DeprecatedMetadataFields {
facebook: null | ResolvedFacebook
pinterest: null | ResolvedPinterest
// common verification tokens
verification: null | ResolvedVerification
......
......@@ -8,6 +8,9 @@ export async function generateMetadata() {
appId: '12345678',
admins: ['120', '122', '124'],
},
pinterest: {
richPin: true,
},
}
return metadata
}
......@@ -162,13 +162,14 @@ describe('app dir - metadata', () => {
)
})
it('should support facebook related tags', async () => {
const browser = await next.browser('/facebook')
it('should support socials related tags like facebook and pinterest', async () => {
const browser = await next.browser('/socials')
const matchMultiDom = createMultiDomMatcher(browser)
await matchMultiDom('meta', 'property', 'content', {
'fb:app_id': '12345678',
'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