-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathstructured-data.js
53 lines (43 loc) · 1.85 KB
/
structured-data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { getSiteUrl } from './url'
function makeFeaturedAppsString ( featuredApps ) {
return featuredApps.slice(0, 5).map(app => app.name).join(', ')
}
export function buildVideoStructuredData ( video, featuredApps, options = {} ) {
// console.log('video', video)
// Throw for missing featured apps
if ( Array.isArray(featuredApps) === false ) {
console.warn( 'featuredApps not array', featuredApps )
throw new Error('featuredApps must be an array of objects')
}
const {
siteUrl = getSiteUrl(),
} = options
const thumbnailUrls = video.thumbnail.srcset.split(',').map( srcSetImage => {
const [ imageUrl ] = srcSetImage.trim().split(' ')
return imageUrl
})
const featuredAppsString = makeFeaturedAppsString( featuredApps )
const embedUrl = new URL( `${ siteUrl }/embed/rich-results-player` )
embedUrl.searchParams.append( 'youtube-id', video.id )
embedUrl.searchParams.append( 'name', video.name )
return {
"@context": "https://schema.org",
// https://developers.google.com/search/docs/data-types/video
// https://schema.org/VideoObject
"@type": "VideoObject",
"name": video.name,
"description": `Includes the following apps: ${featuredAppsString}`,
"thumbnailUrl": thumbnailUrls,
// https://en.wikipedia.org/wiki/ISO_8601
"uploadDate": video.lastUpdated.raw,
// "duration": "PT1M54S", // Need to updaet Youtube API Request for this
// "contentUrl": "https://www.example.com/video/123/file.mp4",
"embedUrl": embedUrl.href,
// "interactionStatistic": {
// "@type": "InteractionCounter",
// "interactionType": { "@type": "http://schema.org/WatchAction" },
// "userInteractionCount": 5647018
// },
// "regionsAllowed": "US,NL"
}
}