date-fns#formatISODuration TypeScript Examples
The following examples show how to use
date-fns#formatISODuration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: tags.ts From atlas with GNU General Public License v3.0 | 4 votes |
generateVideoSchemaTagsHtml = (video: BasicVideoFieldsFragment, thumbnailUrl: string) => {
const videoUrl = joinUrlFragments(BASE_ATLAS_URL, 'video', video.id)
const channelUrl = joinUrlFragments(BASE_ATLAS_URL, 'channel', video.channel.id)
const videoEmbedUrl = joinUrlFragments(BASE_ATLAS_URL, 'embedded', 'video', video.id)
const sanitizedDescription = sanitizeDescription(video.description || '')
const schemaOrgTags: SchemaOrgTag[] = [
{
type: 'link',
prop: 'url',
value: videoUrl,
},
{
type: 'regular',
prop: 'name',
value: video.title,
},
{
type: 'regular',
prop: 'description',
value: sanitizedDescription,
},
{
type: 'regular',
prop: 'channelId',
value: video.channel.id,
},
{
type: 'regular',
prop: 'videoId',
value: video.id,
},
{
type: 'regular',
prop: 'duration',
value: formatISODuration({
seconds: video.duration || 0,
}),
},
{
type: 'regular',
prop: 'unlisted',
value: (!(video.isPublic ?? true)).toString(),
},
{
type: 'regular',
prop: 'thumbnailUrl',
value: thumbnailUrl,
},
{
type: 'link',
prop: 'embedUrl',
value: videoEmbedUrl,
},
{
type: 'regular',
prop: 'playerType',
value: 'HTML5',
},
{
type: 'regular',
prop: 'width',
value: video.mediaMetadata?.pixelWidth || VIDEO_WIDTH,
},
{
type: 'regular',
prop: 'height',
value: video.mediaMetadata?.pixelHeight || VIDEO_HEIGHT,
},
{
type: 'regular',
prop: 'isFamilyFriendly',
value: (!(video.isExplicit ?? true)).toString(),
},
{
type: 'regular',
prop: 'datePublished',
value: video.createdAt,
},
{
type: 'regular',
prop: 'uploadDate',
value: video.createdAt,
},
{
type: 'regular',
prop: 'genre',
value: video.category?.name || '',
},
]
const htmlTags = [
'<div itemscope itemId="" itemtype="http://schema.org/VideoObject">',
...schemaOrgTags.map(({ type, prop, value }) =>
type === 'regular' ? `<meta itemprop="${prop}" content="${value}">` : `<link itemprop="${prop}" href="${value}">`
),
'<span itemprop="author" itemscope itemtype="http://schema.org/Person">',
`<link itemprop="url" href="${channelUrl}">`,
`<meta itemprop="name" content="${video.channel.title || ''}">`,
'</span>',
'<span itemprop="thumbnail" itemscope itemtype="http://schema.org/ImageObject">',
`<link itemprop="url" href="${thumbnailUrl}">`,
`<meta itemprop="width" content="${THUMBNAIL_WIDTH}">`,
`<meta itemprop="height" content="${THUMBNAIL_HEIGHT}">`,
'</span>',
'</div>',
]
return htmlTags.join('\n')
}