1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Add video title/description when rendering html

This commit is contained in:
Chocobozzz 2018-12-14 15:49:36 +01:00
parent a46934c825
commit 9aac44236c
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 41 additions and 28 deletions

View file

@ -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]
static async getDefaultHTMLPage (req: express.Request, res: express.Response, paramLang?: string) {
const html = await ClientHtml.getIndexHTML(req, res, paramLang)
const buffer = await readFile(path)
let customHtml = ClientHtml.addTitleTag(html)
customHtml = ClientHtml.addDescriptionTag(customHtml)
let html = buffer.toString()
html = ClientHtml.addTitleTag(html)
html = ClientHtml.addDescriptionTag(html)
html = ClientHtml.addCustomCSS(html)
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 = '<title>' + CONFIG.INSTANCE.NAME + '</title>'
private static addTitleTag (htmlStringPage: string, title?: string) {
let text = title || CONFIG.INSTANCE.NAME
if (title) text += ` - ${CONFIG.INSTANCE.NAME}`
const titleTag = `<title>${text}</title>`
return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.TITLE, titleTag)
}
private static addDescriptionTag (htmlStringPage: string) {
const descriptionTag = `<meta name="description" content="${CONFIG.INSTANCE.SHORT_DESCRIPTION}" />`
private static addDescriptionTag (htmlStringPage: string, description?: string) {
const content = description || CONFIG.INSTANCE.SHORT_DESCRIPTION
const descriptionTag = `<meta name="description" content="${content}" />`
return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.DESCRIPTION, descriptionTag)
}