Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 093237c

Browse files
committed
Add schema.org tags to videos
1 parent 63c4b44 commit 093237c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

server/controllers/client.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) {
8484
}
8585
]
8686

87+
const schemaTags = {
88+
name: videoNameEscaped,
89+
description: videoDescriptionEscaped,
90+
duration: video.getActivityStreamDuration(),
91+
thumbnailURL: previewUrl,
92+
contentURL: videoUrl,
93+
embedURL: embedUrl,
94+
uploadDate: video.createdAt
95+
}
96+
8797
let tagsString = ''
8898
Object.keys(openGraphMetaTags).forEach(tagName => {
8999
const tagValue = openGraphMetaTags[tagName]
@@ -95,6 +105,16 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) {
95105
tagsString += `<link rel="alternate" type="${oembedLinkTag.type}" href="${oembedLinkTag.href}" title="${oembedLinkTag.title}" />`
96106
}
97107

108+
tagsString += '<div itemprop="video" itemscope itemtype="http://schema.org/VideoObject">'
109+
tagsString += '<h2>Video: <span itemprop="name">' + schemaTags.name + '</span></h2>'
110+
111+
Object.keys(schemaTags).forEach(tagName => {
112+
const tagValue = schemaTags[tagName]
113+
tagsString += `<meta itemprop="${tagName}" content="${tagValue}" />`
114+
})
115+
116+
tagsString += '</div>'
117+
98118
return htmlStringPage.replace(OPENGRAPH_AND_OEMBED_COMMENT, tagsString)
99119
}
100120

server/models/video/video.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,7 @@ export class VideoModel extends Model<VideoModel> {
990990
type: 'Video' as 'Video',
991991
id: this.url,
992992
name: this.name,
993-
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
994-
duration: 'PT' + this.duration + 'S',
993+
duration: this.getActivityStreamDuration(),
995994
uuid: this.uuid,
996995
tag,
997996
category,
@@ -1161,6 +1160,11 @@ export class VideoModel extends Model<VideoModel> {
11611160
return unlinkPromise(torrentPath)
11621161
}
11631162

1163+
getActivityStreamDuration () {
1164+
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
1165+
return 'PT' + this.duration + 'S'
1166+
}
1167+
11641168
private getBaseUrls () {
11651169
let baseUrlHttp
11661170
let baseUrlWs

0 commit comments

Comments
 (0)