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