Enable Video Structured Data on benchmark pages

This commit is contained in:
Sam Carlton 2022-07-06 23:52:55 -05:00
parent c1b232a291
commit da7ae98d5c
3 changed files with 42 additions and 7 deletions

View file

@ -3,6 +3,7 @@ import fs from 'fs-extra'
import pkg from '~/package.json' import pkg from '~/package.json'
import { getSiteUrl } from '~/helpers/url.js' import { getSiteUrl } from '~/helpers/url.js'
import { getRouteType } from '~/helpers/app-derived.js'
export const siteUrl = getSiteUrl() export const siteUrl = getSiteUrl()
@ -232,6 +233,10 @@ export class PageHead {
return this.pageUrl.toString() return this.pageUrl.toString()
} }
get routeType () {
return getRouteType( this.pathname )
}
get defaultMeta () { get defaultMeta () {
return nuxtHead.meta return nuxtHead.meta
} }
@ -310,16 +315,24 @@ export class PageHead {
].join('') ].join('')
} }
get structuredDataMarkup () { get structuredDataMarkup () {
// console.log( 'this.structuredData', this.structuredData ) // console.log( 'this.routeType', this.routeType, this.pathname )
if ( this.structuredData === null ) return '' const hasStructuredData = this.structuredData !== null
// Route is primarily for video
const videoRouteType = [ 'tv', 'benchmarks' ].includes( this.routeType )
if ( hasStructuredData && videoRouteType ) {
const structuredDataJson = JSON.stringify( this.structuredData ) const structuredDataJson = JSON.stringify( this.structuredData )
return `<script type="application/ld+json">${ structuredDataJson }</script>` return `<script type="application/ld+json">${ structuredDataJson }</script>`
} }
return ''
}
get allHeadMarkup () { get allHeadMarkup () {
return [ return [
this.metaMarkup, this.metaMarkup,

View file

@ -183,10 +183,22 @@ export class ListingDetails {
} }
get structuredData () { get structuredData () {
// Normal video page with app links
if ( this.type === 'video' ) { if ( this.type === 'video' ) {
return buildVideoStructuredData( this.api, this.api.appLinks ) return buildVideoStructuredData( this.api, this.api.appLinks )
} }
// Benchmark page
if ( this.hasInitialVideo ) {
// Build app links with just the current app
const appLinks = [ {
name: this.api.name,
endpoint: this.api.endpoint
} ]
return buildVideoStructuredData( this.initialVideo, appLinks )
}
return null return null
} }

View file

@ -40,7 +40,7 @@ const listingsCases = {
endpoint: '/app/expressvpn/benchmarks/', endpoint: '/app/expressvpn/benchmarks/',
apiEndpointPath: '/api/app/expressvpn.json', apiEndpointPath: '/api/app/expressvpn.json',
expectInitialVideo: true, expectInitialVideo: true,
shouldHaveVideoStucturedData: false shouldHaveVideoStucturedData: true
}, },
// Express VPN Benchmarks // Express VPN Benchmarks
@ -193,11 +193,21 @@ test( 'Listings with videos have structured data', async t => {
for ( const [ caseEndpoint, listingCase ] of listingCaseEntries ) { for ( const [ caseEndpoint, listingCase ] of listingCaseEntries ) {
const listingDetails = listingsDetails[ caseEndpoint ] const listingDetails = listingsDetails[ caseEndpoint ]
const listingPageHead = new PageHead( {
...listingDetails.headOptions,
pathname: caseEndpoint
})
// Stop here if we're not expecting Video Structured Data // Stop here if we're not expecting Video Structured Data
if ( !listingCase.shouldHaveVideoStucturedData ) continue if ( !listingCase.shouldHaveVideoStucturedData ) {
// Check that the non-video listing doesn't have video structured data
t.assert( !listingPageHead.structuredDataMarkup.includes('VideoObject'), `${ caseEndpoint } has video structured data` )
continue
}
const listingPageHead = new PageHead( listingDetails.headOptions )
// t.log('listingDetails.initialVideo', listingDetails.initialVideo) // t.log('listingDetails.initialVideo', listingDetails.initialVideo)
// t.log( 'caseEndpoint', caseEndpoint ) // t.log( 'caseEndpoint', caseEndpoint )