aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/client-html.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/client-html.ts')
-rw-r--r--server/lib/client-html.ts56
1 files changed, 45 insertions, 11 deletions
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index d8ae73b5d..85fced10d 100644
--- a/server/lib/client-html.ts
+++ b/server/lib/client-html.ts
@@ -23,6 +23,33 @@ import { CONFIG } from '../initializers/config'
23import { logger } from '../helpers/logger' 23import { logger } from '../helpers/logger'
24import { MAccountActor, MChannelActor } from '../types/models' 24import { MAccountActor, MChannelActor } from '../types/models'
25 25
26type Tags = {
27 ogType: string
28 twitterCard: string
29 schemaType: string
30
31 list?: {
32 numberOfItems: number
33 }
34
35 title: string
36 url: string
37 description: string
38
39 embed?: {
40 url: string
41 createdAt: string
42 duration?: string
43 views?: number
44 }
45
46 image: {
47 url: string
48 width?: number
49 height?: number
50 }
51}
52
26export class ClientHtml { 53export class ClientHtml {
27 54
28 private static htmlCache: { [path: string]: string } = {} 55 private static htmlCache: { [path: string]: string } = {}
@@ -118,15 +145,20 @@ export class ClientHtml {
118 url: videoPlaylist.getThumbnailUrl() 145 url: videoPlaylist.getThumbnailUrl()
119 } 146 }
120 147
148 const embed = {
149 url: WEBSERVER.URL + videoPlaylist.getEmbedStaticPath(),
150 createdAt: videoPlaylist.createdAt.toISOString()
151 }
152
121 const list = { 153 const list = {
122 numberOfItems: videoPlaylist.get('videosLength') 154 numberOfItems: videoPlaylist.get('videosLength') as number
123 } 155 }
124 156
125 const ogType = 'video' 157 const ogType = 'video'
126 const twitterCard = 'summary' 158 const twitterCard = CONFIG.SERVICES.TWITTER.WHITELISTED ? 'player' : 'summary'
127 const schemaType = 'ItemList' 159 const schemaType = 'ItemList'
128 160
129 customHtml = ClientHtml.addTags(customHtml, { url, title, description, image, list, ogType, twitterCard, schemaType }) 161 customHtml = ClientHtml.addTags(customHtml, { url, embed, title, description, image, list, ogType, twitterCard, schemaType })
130 162
131 return customHtml 163 return customHtml
132 } 164 }
@@ -268,7 +300,7 @@ export class ClientHtml {
268 return htmlStringPage.replace('</head>', linkTag + '</head>') 300 return htmlStringPage.replace('</head>', linkTag + '</head>')
269 } 301 }
270 302
271 private static generateOpenGraphMetaTags (tags) { 303 private static generateOpenGraphMetaTags (tags: Tags) {
272 const metaTags = { 304 const metaTags = {
273 'og:type': tags.ogType, 305 'og:type': tags.ogType,
274 'og:title': tags.title, 306 'og:title': tags.title,
@@ -294,7 +326,7 @@ export class ClientHtml {
294 return metaTags 326 return metaTags
295 } 327 }
296 328
297 private static generateStandardMetaTags (tags) { 329 private static generateStandardMetaTags (tags: Tags) {
298 return { 330 return {
299 name: tags.title, 331 name: tags.title,
300 description: tags.description, 332 description: tags.description,
@@ -302,7 +334,7 @@ export class ClientHtml {
302 } 334 }
303 } 335 }
304 336
305 private static generateTwitterCardMetaTags (tags) { 337 private static generateTwitterCardMetaTags (tags: Tags) {
306 const metaTags = { 338 const metaTags = {
307 'twitter:card': tags.twitterCard, 339 'twitter:card': tags.twitterCard,
308 'twitter:site': CONFIG.SERVICES.TWITTER.USERNAME, 340 'twitter:site': CONFIG.SERVICES.TWITTER.USERNAME,
@@ -319,7 +351,7 @@ export class ClientHtml {
319 return metaTags 351 return metaTags
320 } 352 }
321 353
322 private static generateSchemaTags (tags) { 354 private static generateSchemaTags (tags: Tags) {
323 const schema = { 355 const schema = {
324 '@context': 'http://schema.org', 356 '@context': 'http://schema.org',
325 '@type': tags.schemaType, 357 '@type': tags.schemaType,
@@ -337,8 +369,10 @@ export class ClientHtml {
337 if (tags.embed) { 369 if (tags.embed) {
338 schema['embedUrl'] = tags.embed.url 370 schema['embedUrl'] = tags.embed.url
339 schema['uploadDate'] = tags.embed.createdAt 371 schema['uploadDate'] = tags.embed.createdAt
340 schema['duration'] = tags.embed.duration 372
341 schema['iterationCount'] = tags.embed.views 373 if (tags.embed.duration) schema['duration'] = tags.embed.duration
374 if (tags.embed.views) schema['iterationCount'] = tags.embed.views
375
342 schema['thumbnailUrl'] = tags.image.url 376 schema['thumbnailUrl'] = tags.image.url
343 schema['contentUrl'] = tags.url 377 schema['contentUrl'] = tags.url
344 } 378 }
@@ -346,7 +380,7 @@ export class ClientHtml {
346 return schema 380 return schema
347 } 381 }
348 382
349 private static addTags (htmlStringPage: string, tagsValues: any) { 383 private static addTags (htmlStringPage: string, tagsValues: Tags) {
350 const openGraphMetaTags = this.generateOpenGraphMetaTags(tagsValues) 384 const openGraphMetaTags = this.generateOpenGraphMetaTags(tagsValues)
351 const standardMetaTags = this.generateStandardMetaTags(tagsValues) 385 const standardMetaTags = this.generateStandardMetaTags(tagsValues)
352 const twitterCardMetaTags = this.generateTwitterCardMetaTags(tagsValues) 386 const twitterCardMetaTags = this.generateTwitterCardMetaTags(tagsValues)
@@ -354,7 +388,7 @@ export class ClientHtml {
354 388
355 const { url, title, embed } = tagsValues 389 const { url, title, embed } = tagsValues
356 390
357 const oembedLinkTags = [] 391 const oembedLinkTags: { type: string, href: string, title: string }[] = []
358 392
359 if (embed) { 393 if (embed) {
360 oembedLinkTags.push({ 394 oembedLinkTags.push({