diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-14 15:49:36 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-17 09:13:22 +0100 |
commit | 9aac44236c84f17b14ce35e358a87389766e2743 (patch) | |
tree | 7c17980eb31d2951aabe0113138cbd33a9992bdb /server/lib | |
parent | a46934c825d5dea4154fb100abf26ec3bc28d5a4 (diff) | |
download | PeerTube-9aac44236c84f17b14ce35e358a87389766e2743.tar.gz PeerTube-9aac44236c84f17b14ce35e358a87389766e2743.tar.zst PeerTube-9aac44236c84f17b14ce35e358a87389766e2743.zip |
Add video title/description when rendering html
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/client-html.ts | 51 |
1 files changed, 33 insertions, 18 deletions
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 { | |||
18 | ClientHtml.htmlCache = {} | 18 | ClientHtml.htmlCache = {} |
19 | } | 19 | } |
20 | 20 | ||
21 | static async getIndexHTML (req: express.Request, res: express.Response, paramLang?: string) { | 21 | static async getDefaultHTMLPage (req: express.Request, res: express.Response, paramLang?: string) { |
22 | const path = ClientHtml.getIndexPath(req, res, paramLang) | 22 | const html = await ClientHtml.getIndexHTML(req, res, paramLang) |
23 | if (ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] | ||
24 | |||
25 | const buffer = await readFile(path) | ||
26 | 23 | ||
27 | let html = buffer.toString() | 24 | let customHtml = ClientHtml.addTitleTag(html) |
28 | 25 | customHtml = ClientHtml.addDescriptionTag(customHtml) | |
29 | html = ClientHtml.addTitleTag(html) | ||
30 | html = ClientHtml.addDescriptionTag(html) | ||
31 | html = ClientHtml.addCustomCSS(html) | ||
32 | 26 | ||
33 | ClientHtml.htmlCache[path] = html | 27 | return customHtml |
34 | |||
35 | return html | ||
36 | } | 28 | } |
37 | 29 | ||
38 | static async getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) { | 30 | static async getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) { |
@@ -55,7 +47,26 @@ export class ClientHtml { | |||
55 | return ClientHtml.getIndexHTML(req, res) | 47 | return ClientHtml.getIndexHTML(req, res) |
56 | } | 48 | } |
57 | 49 | ||
58 | return ClientHtml.addOpenGraphAndOEmbedTags(html, video) | 50 | let customHtml = ClientHtml.addTitleTag(html, escapeHTML(video.name)) |
51 | customHtml = ClientHtml.addDescriptionTag(customHtml, escapeHTML(video.description)) | ||
52 | customHtml = ClientHtml.addOpenGraphAndOEmbedTags(customHtml, video) | ||
53 | |||
54 | return customHtml | ||
55 | } | ||
56 | |||
57 | private static async getIndexHTML (req: express.Request, res: express.Response, paramLang?: string) { | ||
58 | const path = ClientHtml.getIndexPath(req, res, paramLang) | ||
59 | if (ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] | ||
60 | |||
61 | const buffer = await readFile(path) | ||
62 | |||
63 | let html = buffer.toString() | ||
64 | |||
65 | html = ClientHtml.addCustomCSS(html) | ||
66 | |||
67 | ClientHtml.htmlCache[path] = html | ||
68 | |||
69 | return html | ||
59 | } | 70 | } |
60 | 71 | ||
61 | private static getIndexPath (req: express.Request, res: express.Response, paramLang?: string) { | 72 | private static getIndexPath (req: express.Request, res: express.Response, paramLang?: string) { |
@@ -81,14 +92,18 @@ export class ClientHtml { | |||
81 | return join(__dirname, '../../../client/dist/' + buildFileLocale(lang) + '/index.html') | 92 | return join(__dirname, '../../../client/dist/' + buildFileLocale(lang) + '/index.html') |
82 | } | 93 | } |
83 | 94 | ||
84 | private static addTitleTag (htmlStringPage: string) { | 95 | private static addTitleTag (htmlStringPage: string, title?: string) { |
85 | const titleTag = '<title>' + CONFIG.INSTANCE.NAME + '</title>' | 96 | let text = title || CONFIG.INSTANCE.NAME |
97 | if (title) text += ` - ${CONFIG.INSTANCE.NAME}` | ||
98 | |||
99 | const titleTag = `<title>${text}</title>` | ||
86 | 100 | ||
87 | return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.TITLE, titleTag) | 101 | return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.TITLE, titleTag) |
88 | } | 102 | } |
89 | 103 | ||
90 | private static addDescriptionTag (htmlStringPage: string) { | 104 | private static addDescriptionTag (htmlStringPage: string, description?: string) { |
91 | const descriptionTag = `<meta name="description" content="${CONFIG.INSTANCE.SHORT_DESCRIPTION}" />` | 105 | const content = description || CONFIG.INSTANCE.SHORT_DESCRIPTION |
106 | const descriptionTag = `<meta name="description" content="${content}" />` | ||
92 | 107 | ||
93 | return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.DESCRIPTION, descriptionTag) | 108 | return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.DESCRIPTION, descriptionTag) |
94 | } | 109 | } |