From f45d48db1d560f64d2aa75f028617bb3aa0d9051 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 15 May 2021 18:01:02 -0500 Subject: [PATCH] Move buildVideoStructuredData to helper --- helpers/structured-data.js | 45 ++++++++++++++++++++++++++++++++++++++ pages/tv/_slug.vue | 43 +++++------------------------------- 2 files changed, 50 insertions(+), 38 deletions(-) create mode 100644 helpers/structured-data.js diff --git a/helpers/structured-data.js b/helpers/structured-data.js new file mode 100644 index 0000000..a4800fd --- /dev/null +++ b/helpers/structured-data.js @@ -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" + } +} diff --git a/pages/tv/_slug.vue b/pages/tv/_slug.vue index dc7a4dc..eed6ad1 100644 --- a/pages/tv/_slug.vue +++ b/pages/tv/_slug.vue @@ -81,6 +81,8 @@ import { getAppEndpoint } from '~/helpers/app-derived.js' +import { buildVideoStructuredData } from '~/helpers/structure-data.js' + import LinkButton from '~/components/link-button.vue' import EmailSubscribe from '~/components/email-subscribe.vue' import VideoRow from '~/components/video/row.vue' @@ -93,43 +95,6 @@ function makeFeaturedAppsString ( featuredApps ) { } -function buildVideoStructuredData ( video, featuredApps ) { - // console.log('video', video) - - const thumbnailUrls = video.thumbnail.srcset.split(',').map( srcSetImage => { - const [ imageUrl ] = srcSetImage.trim().split(' ') - - return imageUrl - }) - - const featuredAppsString = makeFeaturedAppsString( featuredApps ) - - const embedUrl = new URL( `${ this.$config.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" - } -} export default { components: { LinkButton, @@ -184,7 +149,9 @@ export default { getAppEndpoint }, head() { - const structuredData = buildVideoStructuredData.bind(this)( this.video, this.featuredApps ) + const structuredData = buildVideoStructuredData( this.video, this.featuredApps, { + siteUrl: this.$config.siteUrl + } ) return {