Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Vidéos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Vidéos
Commits
9aac4423
Unverified
Commit
9aac4423
authored
6 years ago
by
Chocobozzz
Browse files
Options
Downloads
Patches
Plain Diff
Add video title/description when rendering html
parent
a46934c8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/controllers/client.ts
+8
-10
8 additions, 10 deletions
server/controllers/client.ts
server/lib/client-html.ts
+33
-18
33 additions, 18 deletions
server/lib/client-html.ts
with
41 additions
and
28 deletions
server/controllers/client.ts
+
8
−
10
View file @
9aac4423
...
...
@@ -16,22 +16,20 @@ const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
// Special route that add OpenGraph and oEmbed tags
// Do not use a template engine for a so little thing
clientsRouter
.
use
(
'
/videos/watch/:id
'
,
asyncMiddleware
(
generateWatchHtmlPage
)
)
clientsRouter
.
use
(
'
/videos/watch/:id
'
,
asyncMiddleware
(
generateWatchHtmlPage
))
clientsRouter
.
use
(
''
+
clientsRouter
.
use
(
'
/videos/embed
'
,
embedCSP
,
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
(
req
:
express
.
Request
,
res
:
express
.
Response
)
=>
{
res
.
removeHeader
(
'
X-Frame-Options
'
)
res
.
sendFile
(
embedPath
)
}
)
clientsRouter
.
use
(
''
+
'
/videos/test-embed
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
res
.
sendFile
(
testEmbedPath
)
}
)
clientsRouter
.
use
(
'
/videos/test-embed
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
)
=>
res
.
sendFile
(
testEmbedPath
)
)
// Static HTML/CSS/JS client files
...
...
@@ -90,7 +88,7 @@ export {
// ---------------------------------------------------------------------------
async
function
generateHTMLPage
(
req
:
express
.
Request
,
res
:
express
.
Response
,
paramLang
?:
string
)
{
const
html
=
await
ClientHtml
.
get
IndexHTML
(
req
,
res
,
paramLang
)
const
html
=
await
ClientHtml
.
get
DefaultHTMLPage
(
req
,
res
,
paramLang
)
return
sendHTML
(
html
,
res
)
}
...
...
This diff is collapsed.
Click to expand it.
server/lib/client-html.ts
+
33
−
18
View file @
9aac4423
...
...
@@ -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
=
'
<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
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment