From 9aac44236c84f17b14ce35e358a87389766e2743 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 14 Dec 2018 15:49:36 +0100 Subject: Add video title/description when rendering html --- server/lib/client-html.ts | 51 ++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'server/lib/client-html.ts') diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index fc013e0c3..2db3f8a34 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -18,21 +18,13 @@ export class ClientHtml { ClientHtml.htmlCache = {} } - static async getIndexHTML (req: express.Request, res: express.Response, paramLang?: string) { - const path = ClientHtml.getIndexPath(req, res, paramLang) - if (ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] - - const buffer = await readFile(path) + static async getDefaultHTMLPage (req: express.Request, res: express.Response, paramLang?: string) { + const html = await ClientHtml.getIndexHTML(req, res, paramLang) - let html = buffer.toString() - - html = ClientHtml.addTitleTag(html) - html = ClientHtml.addDescriptionTag(html) - html = ClientHtml.addCustomCSS(html) + let customHtml = ClientHtml.addTitleTag(html) + customHtml = ClientHtml.addDescriptionTag(customHtml) - ClientHtml.htmlCache[path] = html - - return html + return customHtml } static async getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) { @@ -55,7 +47,26 @@ export class ClientHtml { return ClientHtml.getIndexHTML(req, res) } - return ClientHtml.addOpenGraphAndOEmbedTags(html, video) + let customHtml = ClientHtml.addTitleTag(html, escapeHTML(video.name)) + customHtml = ClientHtml.addDescriptionTag(customHtml, escapeHTML(video.description)) + customHtml = ClientHtml.addOpenGraphAndOEmbedTags(customHtml, video) + + return customHtml + } + + private static async getIndexHTML (req: express.Request, res: express.Response, paramLang?: string) { + const path = ClientHtml.getIndexPath(req, res, paramLang) + if (ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] + + const buffer = await readFile(path) + + let html = buffer.toString() + + html = ClientHtml.addCustomCSS(html) + + ClientHtml.htmlCache[path] = html + + return html } private static getIndexPath (req: express.Request, res: express.Response, paramLang?: string) { @@ -81,14 +92,18 @@ export class ClientHtml { return join(__dirname, '../../../client/dist/' + buildFileLocale(lang) + '/index.html') } - private static addTitleTag (htmlStringPage: string) { - const titleTag = '' + CONFIG.INSTANCE.NAME + '' + private static addTitleTag (htmlStringPage: string, title?: string) { + let text = title || CONFIG.INSTANCE.NAME + if (title) text += ` - ${CONFIG.INSTANCE.NAME}` + + const titleTag = `${text}` return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.TITLE, titleTag) } - private static addDescriptionTag (htmlStringPage: string) { - const descriptionTag = `` + private static addDescriptionTag (htmlStringPage: string, description?: string) { + const content = description || CONFIG.INSTANCE.SHORT_DESCRIPTION + const descriptionTag = `` return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.DESCRIPTION, descriptionTag) } -- cgit v1.2.3 From cef534ed53e4518fe0acf581bfe880788d42fc36 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Dec 2018 10:36:24 +0100 Subject: Add user notification base code --- server/lib/client-html.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'server/lib/client-html.ts') diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 2db3f8a34..1875ec1fc 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -115,8 +115,8 @@ export class ClientHtml { } private static addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) { - const previewUrl = CONFIG.WEBSERVER.URL + STATIC_PATHS.PREVIEWS + video.getPreviewName() - const videoUrl = CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + const previewUrl = CONFIG.WEBSERVER.URL + video.getPreviewStaticPath() + const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() const videoNameEscaped = escapeHTML(video.name) const videoDescriptionEscaped = escapeHTML(video.description) -- cgit v1.2.3 From c04eb647db4f543a31a8100c1ec9a86c700bca6a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 10 Jan 2019 16:00:23 +0100 Subject: Use origin video url in canonical tag --- server/lib/client-html.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'server/lib/client-html.ts') diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 1875ec1fc..b2c376e20 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -1,7 +1,7 @@ import * as express from 'express' import * as Bluebird from 'bluebird' import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n' -import { CONFIG, CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE, STATIC_PATHS } from '../initializers' +import { CONFIG, CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE } from '../initializers' import { join } from 'path' import { escapeHTML } from '../helpers/core-utils' import { VideoModel } from '../models/video/video' @@ -187,8 +187,8 @@ export class ClientHtml { // Schema.org tagsString += `` - // SEO - tagsString += `` + // SEO, use origin video url so Google does not index remote videos + tagsString += `` return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.OPENGRAPH_AND_OEMBED, tagsString) } -- cgit v1.2.3