Skip to content

Commit

Permalink
Add multiple directors support in movie carousel (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
valse committed Jan 28, 2021
1 parent 051896f commit 0546e1e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1959,9 +1959,14 @@ export default () => (
url: 'http://example.com/movie-1.html',
image:
'https://i.pinimg.com/originals/96/a0/0d/96a00d42b0ff8f80b7cdf2926a211e47.jpg',
director: {
name: 'Mary Doe',
},
director: [
{
name: 'Mary Doe',
},
{
name: 'John Doe',
},
],
review: {
author: { type: 'Person', name: 'Ronan Farrow' },
reviewBody:
Expand All @@ -1987,7 +1992,7 @@ export default () => (

| Property | Info |
| ----------------- | -------------------------------------- |
| `director` | The director of the movie. |
| `director` | The directors of the movie. |
| `dateCreated` | The date the movie was released. |
| `aggregateRating` | Aggregate Rating object for the movie. |
| `review` | Review for the movie. |
Expand Down
23 changes: 17 additions & 6 deletions src/jsonld/carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface MovieJsonLdProps {
url: string;
image: string;
dateCreated?: string;
director?: Director;
director?: Director | Director[];
review?: Review;
aggregateRating?: AggregateRating;
}
Expand Down Expand Up @@ -101,11 +101,22 @@ const CarouselJsonLd: FC<CarouselJsonLdProps> = ({ type, data }) => {
"image": "${item.image}",
${item.dateCreated ? `"dateCreated": "${item.dateCreated}",` : ``}
${
item.director?.name
? `"director": {
"@type": "Person",
"name": "${item.director.name}"
}`
item.director
? `"director": ${
Array.isArray(item.director)
? `[${item.director
.map(
director => `{
"@type": "Person",
"name": "${director.name}"
}`,
)
.join(',')}]`
: `{
"@type": "Person",
"name": "${item.director.name}"
}`
}`
: ''
}
${
Expand Down
37 changes: 25 additions & 12 deletions src/utils/buildVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,40 @@ export default (video: Video, context: boolean = false) => `{
"name": "${video.name}",
"description": "${video.description}",
"thumbnailUrl": [
${video.thumbnailUrls.map(thumbnailUrl => `"${thumbnailUrl}"`).join(',')}
${video.thumbnailUrls
.map(thumbnailUrl => `"${thumbnailUrl}"`)
.join(',')}
],
${video.contentUrl ? `"contentUrl": "${video.contentUrl}",` : ``}
${video.duration ? `"duration": "${video.duration}",` : ``}
${video.embedUrl ? `"embedUrl": "${video.embedUrl}",` : ``}
${video.expires ? `"expires": "${video.expires}",` : ``}
${video.
hasPart
${
video.hasPart
? `"hasPart": ${
Array.isArray(video.hasPart)
? `[${video.hasPart.map(clip => `${buildClip(clip)}`)}]`
? `[${video.hasPart
.map(clip => `${buildClip(clip)}`)
.join(',')}]`
: buildClip(video.hasPart)
},`
: ''
}
${video.watchCount ? `${buildInteractionStatistic(video.watchCount)}` : ``}
${video.
publication
${
video.watchCount
? `${buildInteractionStatistic(video.watchCount)}`
: ``
}
${
video.publication
? `"publication": ${
Array.isArray(video.publication)
? `[${video.publication.map(broadcastEvent => `${buildBroadcastEvent(broadcastEvent)}`)}]`
? `[${video.publication
.map(
broadcastEvent =>
`${buildBroadcastEvent(broadcastEvent)}`,
)
.join(',')}]`
: buildBroadcastEvent(video.publication)
},`
: ''
Expand All @@ -40,13 +53,13 @@ export default (video: Video, context: boolean = false) => `{
"uploadDate": "${video.uploadDate}"
}`;

const buildClip = (clip: Clip) => `
const buildClip = (clip: Clip) => `
"geo": {
"@type": "Clip",
"name": "${clip.name}",
"startOffset": ${clip.startOffset},
"url": "${clip.url}",
},
"url": "${clip.url}"
}
`;

const buildInteractionStatistic = (watchCount: number) => `
Expand All @@ -64,5 +77,5 @@ const buildBroadcastEvent = (publication: BroadcastEvent) => `
"isLiveBroadcast": ${publication.isLiveBroadcast},
"startDate": "${publication.startDate}",
"endDate": "${publication.endDate}"
},
}
`;

0 comments on commit 0546e1e

Please sign in to comment.