@@ -3,6 +3,7 @@ import { Helmet } from 'react-helmet';
33import { RequestContext } from '#contexts/RequestContext' ;
44import serialiseForScript from '#lib/utilities/serialiseForScript' ;
55import getBrandedImage from '#lib/utilities/getBrandedImage' ;
6+ import { Services } from '#app/models/types/global' ;
67import { ServiceContext } from '../../contexts/ServiceContext' ;
78import getAboutTagsContent from './getAboutTagsContent' ;
89import { BylineLinkedData , LinkedDataProps } from './types' ;
@@ -28,6 +29,34 @@ type AuthorStructure = {
2829
2930type Author = AuthorStructure | AuthorStructure [ ] ;
3031
32+ type SpeakableSpecification = {
33+ '@type' : 'SpeakableSpecification' ;
34+ xpath : string [ ] ;
35+ } ;
36+
37+ const SPEAKABLE_ENABLED_SERVICES = [ 'hindi' ] ; // TODO: to be extended
38+ const SUPPORTED_SPEAKABLE_TYPES = [ 'WebPage' ] ;
39+
40+ const getSpeakableXpaths = ( {
41+ service,
42+ seoTitle,
43+ type,
44+ } : {
45+ service : Services ;
46+ seoTitle ?: string ;
47+ type : string ;
48+ } ) : SpeakableSpecification [ ] | null => {
49+ if ( ! SUPPORTED_SPEAKABLE_TYPES . includes ( type ) ) return null ;
50+ if ( ! SPEAKABLE_ENABLED_SERVICES . includes ( service ) ) return null ;
51+ if ( ! seoTitle ) return null ;
52+ return [
53+ {
54+ '@type' : 'SpeakableSpecification' ,
55+ xpath : [ '/html/head/title' ] ,
56+ } ,
57+ ] ;
58+ } ;
59+
3160const LinkedData = ( {
3261 showAuthor = false ,
3362 type,
@@ -177,6 +206,13 @@ const LinkedData = ({
177206 if ( hasByline && bylineAuthors && bylineAuthors . length > 0 ) {
178207 author = bylineAuthors . length === 1 ? bylineAuthors [ 0 ] : bylineAuthors ;
179208 }
209+
210+ const speakableXpaths = getSpeakableXpaths ( {
211+ service,
212+ seoTitle,
213+ type,
214+ } ) ;
215+
180216 const linkedData = {
181217 '@type' : type ,
182218 url : canonicalNonUkLink ,
@@ -191,10 +227,9 @@ const LinkedData = ({
191227 coverageEndTime,
192228 inLanguage,
193229 ...( aboutTags && { about : getAboutTagsContent ( aboutTags ) } ) ,
194- ...( showAuthor && {
195- author,
196- } ) ,
230+ ...( showAuthor && { author } ) ,
197231 ...( hasByline && places . length > 0 && { locationCreated } ) ,
232+ ...( speakableXpaths && { speakable : speakableXpaths } ) ,
198233 } ;
199234
200235 return (
0 commit comments