]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/client.ts
Add ability to embed a video in Twitter
[github/Chocobozzz/PeerTube.git] / server / controllers / client.ts
index 39e046727291714afa75ded7b1a0945dfd8f859b..20f7e5c9c2a613abee62adb73310615c11f991b5 100644 (file)
@@ -10,7 +10,7 @@ import { VideoModel } from '../models/video/video'
 const clientsRouter = express.Router()
 
 const distPath = join(root(), 'client', 'dist')
-const assetsImagesPath = join(root(), 'client', 'dist', 'client', 'assets', 'images')
+const assetsImagesPath = join(root(), 'client', 'dist', 'assets', 'images')
 const embedPath = join(distPath, 'standalone', 'videos', 'embed.html')
 const indexPath = join(distPath, 'index.html')
 
@@ -25,6 +25,17 @@ clientsRouter.use('/videos/embed', (req: express.Request, res: express.Response,
 })
 
 // Static HTML/CSS/JS client files
+
+const staticClientFiles = [
+  'manifest.json',
+  'ngsw-worker.js',
+  'ngsw.json'
+]
+for (const staticClientFile of staticClientFiles) {
+  const path = join(root(), 'client', 'dist', staticClientFile)
+  clientsRouter.use('/' + staticClientFile, express.static(path, { maxAge: STATIC_MAX_AGE }))
+}
+
 clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE }))
 clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE }))
 
@@ -66,8 +77,8 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) {
     'description': videoDescriptionEscaped,
     'image': previewUrl,
 
-    'twitter:card': 'summary_large_image',
-    'twitter:site': '@Chocobozzz',
+    'twitter:card': CONFIG.SERVICES.TWITTER.WHITELISTED ? 'player' : 'summary_large_image',
+    'twitter:site': CONFIG.SERVICES.TWITTER.USERNAME,
     'twitter:title': videoNameEscaped,
     'twitter:description': videoDescriptionEscaped,
     'twitter:image': previewUrl,
@@ -84,17 +95,39 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) {
     }
   ]
 
+  const schemaTags = {
+    '@context': 'http://schema.org',
+    '@type': 'VideoObject',
+    name: videoNameEscaped,
+    description: videoDescriptionEscaped,
+    thumbnailUrl: previewUrl,
+    uploadDate: video.createdAt.toISOString(),
+    duration: video.getActivityStreamDuration(),
+    contentUrl: videoUrl,
+    embedUrl: embedUrl,
+    interactionCount: video.views
+  }
+
   let tagsString = ''
+
+  // Opengraph
   Object.keys(openGraphMetaTags).forEach(tagName => {
     const tagValue = openGraphMetaTags[tagName]
 
     tagsString += `<meta property="${tagName}" content="${tagValue}" />`
   })
 
+  // OEmbed
   for (const oembedLinkTag of oembedLinkTags) {
     tagsString += `<link rel="alternate" type="${oembedLinkTag.type}" href="${oembedLinkTag.href}" title="${oembedLinkTag.title}" />`
   }
 
+  // Schema.org
+  tagsString += `<script type="application/ld+json">${JSON.stringify(schemaTags)}</script>`
+
+  // SEO
+  tagsString += `<link rel="canonical" href="${videoUrl}" />`
+
   return htmlStringPage.replace(OPENGRAPH_AND_OEMBED_COMMENT, tagsString)
 }