-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project): add structured data for movie and series screens
- Loading branch information
1 parent
a4ba9d4
commit 2a6df70
Showing
6 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Seconds to ISO8601 duration or date string | ||
*/ | ||
export function secondsToISO8601 (input: number, timeOnly: boolean = false): string { | ||
if (!input) { | ||
return ''; | ||
} | ||
|
||
const date = new Date(input ? input * 1000 : 0); | ||
const hours = date.getUTCHours(); | ||
const minutes = date.getUTCMinutes(); | ||
const seconds = date.getUTCSeconds(); | ||
|
||
if (!timeOnly) { | ||
return date.toISOString(); | ||
} | ||
|
||
let isoString = 'PT'; | ||
if (hours > 0) isoString += hours + 'H'; | ||
if (minutes > 0) isoString += minutes + 'M'; | ||
if (seconds > 0) isoString += seconds + 'S'; | ||
|
||
return isoString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { Playlist, PlaylistItem } from '../../types/playlist'; | ||
|
||
import { episodeURL, movieURL } from './formatting'; | ||
import { secondsToISO8601 } from './datetime'; | ||
|
||
export const generateSeriesMetadata = (seriesPlaylist: Playlist) => { | ||
const seriesCanonical = `${window.location.origin}/${episodeURL(seriesPlaylist)}`; | ||
|
||
return { | ||
'@type': 'TVSeries', | ||
'@id': seriesCanonical, | ||
name: seriesPlaylist.title, | ||
numberOfEpisodes: seriesPlaylist.playlist.length, | ||
numberOfSeasons: seriesPlaylist.playlist.reduce(function (list, playlistItem) { | ||
return !playlistItem.seasonNumber || list.includes(playlistItem.seasonNumber) ? list : list.concat(playlistItem.seasonNumber); | ||
}, [] as string[]).length | ||
}; | ||
} | ||
|
||
export const generateEpisodeJSONLD = (seriesPlaylist: Playlist, episode: PlaylistItem) => { | ||
const episodeCanonical = `${window.location.origin}/${episodeURL(seriesPlaylist, episode.mediaid)}`; | ||
const seriesMetadata = generateSeriesMetadata(seriesPlaylist); | ||
|
||
return JSON.stringify({ | ||
'@context': 'http://schema.org/', | ||
'@type': 'TVEpisode', | ||
'@id': episodeCanonical, | ||
episodeNumber: episode.episodeNumber, | ||
seasonNumber: episode.seasonNumber, | ||
name: episode.title, | ||
uploadDate: secondsToISO8601(episode.pubdate), | ||
partOfSeries: seriesMetadata, | ||
}); | ||
} | ||
|
||
export const generateMovieJSONLD = (item: PlaylistItem) => { | ||
const movieCanonical = `${window.location.origin}/${movieURL(item)}`; | ||
|
||
return JSON.stringify({ | ||
'@context': 'http://schema.org/', | ||
'@type': 'VideoObject', | ||
'@id': movieCanonical, | ||
name: item.title, | ||
description: item.description, | ||
duration: secondsToISO8601(item.duration, true), | ||
thumbnailUrl: item.image, | ||
uploadDate: secondsToISO8601(item.pubdate) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters