]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/client-html.ts
Merge branch 'release/3.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / client-html.ts
index a557c090f0207faed553627dc762007233a65708..84b4ca97def8477dd034e2d85a7366e36c4e8a7e 100644 (file)
@@ -1,4 +1,4 @@
-import * as express from 'express'
+import express from 'express'
 import { readFile } from 'fs-extra'
 import { join } from 'path'
 import validator from 'validator'
@@ -44,6 +44,8 @@ type Tags = {
   originUrl: string
   description: string
 
+  disallowIndexation?: boolean
+
   embed?: {
     url: string
     createdAt: string
@@ -285,7 +287,8 @@ class ClientHtml {
       image,
       ogType,
       twitterCard,
-      schemaType
+      schemaType,
+      disallowIndexation: !entity.Actor.isOwned()
     })
 
     return customHtml
@@ -300,7 +303,6 @@ class ClientHtml {
 
     let html = buffer.toString()
 
-    if (paramLang) html = ClientHtml.addHtmlLang(html, paramLang)
     html = ClientHtml.addManifestContentHash(html)
     html = ClientHtml.addFaviconContentHash(html)
     html = ClientHtml.addLogoContentHash(html)
@@ -379,8 +381,9 @@ class ClientHtml {
   }
 
   private static addServerConfig (htmlStringPage: string, serverConfig: HTMLServerConfig) {
-    const serverConfigString = JSON.stringify(serverConfig)
-    const configScriptTag = `<script type="application/javascript">window.PeerTubeServerConfig = '${serverConfigString}'</script>`
+    // Stringify the JSON object, and then stringify the string object so we can inject it into the HTML
+    const serverConfigString = JSON.stringify(JSON.stringify(serverConfig))
+    const configScriptTag = `<script type="application/javascript">window.PeerTubeServerConfig = ${serverConfigString}</script>`
 
     return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.SERVER_CONFIG, configScriptTag)
   }
@@ -488,7 +491,7 @@ class ClientHtml {
     const twitterCardMetaTags = this.generateTwitterCardMetaTags(tagsValues)
     const schemaTags = this.generateSchemaTags(tagsValues)
 
-    const { url, title, embed, originUrl } = tagsValues
+    const { url, title, embed, originUrl, disallowIndexation } = tagsValues
 
     const oembedLinkTags: { type: string, href: string, title: string }[] = []
 
@@ -536,6 +539,10 @@ class ClientHtml {
     // SEO, use origin URL
     tagsString += `<link rel="canonical" href="${originUrl}" />`
 
+    if (disallowIndexation) {
+      tagsString += `<meta name="robots" content="noindex" />`
+    }
+
     return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.META_TAGS, tagsString)
   }
 }
@@ -547,8 +554,7 @@ function sendHTML (html: string, res: express.Response) {
 }
 
 async function serveIndexHTML (req: express.Request, res: express.Response) {
-  if (req.accepts(ACCEPT_HEADERS) === 'html' ||
-      !req.headers.accept) {
+  if (req.accepts(ACCEPT_HEADERS) === 'html' || !req.headers.accept) {
     try {
       await generateHTMLPage(req, res, req.params.language)
       return