Move buildVideoStructuredData to helper

This commit is contained in:
Sam Carlton 2021-05-15 18:01:02 -05:00
parent 911b67d569
commit f45d48db1d
2 changed files with 50 additions and 38 deletions

View file

@ -0,0 +1,45 @@
function makeFeaturedAppsString ( featuredApps ) {
return featuredApps.slice(0, 5).map(app => app.name).join(', ')
}
export function buildVideoStructuredData ( video, featuredApps, options ) {
// console.log('video', video)
const {
siteUrl
} = 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"
}
}