From: Chocobozzz Date: Tue, 23 Jan 2018 16:09:06 +0000 (+0100) Subject: Add schema.org tags to videos X-Git-Tag: v0.0.14-alpha~1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=093237cf79ea62207b51dd632a4c4fd1f74d71fd;p=github%2FChocobozzz%2FPeerTube.git Add schema.org tags to videos --- diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 39e046727..bb02f5075 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts @@ -84,6 +84,16 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) { } ] + const schemaTags = { + name: videoNameEscaped, + description: videoDescriptionEscaped, + duration: video.getActivityStreamDuration(), + thumbnailURL: previewUrl, + contentURL: videoUrl, + embedURL: embedUrl, + uploadDate: video.createdAt + } + let tagsString = '' Object.keys(openGraphMetaTags).forEach(tagName => { const tagValue = openGraphMetaTags[tagName] @@ -95,6 +105,16 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) { tagsString += `` } + tagsString += '
' + tagsString += '

Video: ' + schemaTags.name + '

' + + Object.keys(schemaTags).forEach(tagName => { + const tagValue = schemaTags[tagName] + tagsString += `` + }) + + tagsString += '
' + return htmlStringPage.replace(OPENGRAPH_AND_OEMBED_COMMENT, tagsString) } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 77c0400d8..81d8a64ff 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -990,8 +990,7 @@ export class VideoModel extends Model { type: 'Video' as 'Video', id: this.url, name: this.name, - // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration - duration: 'PT' + this.duration + 'S', + duration: this.getActivityStreamDuration(), uuid: this.uuid, tag, category, @@ -1161,6 +1160,11 @@ export class VideoModel extends Model { return unlinkPromise(torrentPath) } + getActivityStreamDuration () { + // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration + return 'PT' + this.duration + 'S' + } + private getBaseUrls () { let baseUrlHttp let baseUrlWs