mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 02:09:37 +02:00
Fix SEO and refactor HTML pages generation
* Split methods in multiple classes * Add JSONLD tags in embed too * Index embeds but use a canonical URL tag (targeting the watch page) * Remote objects don't include a canonical URL tag anymore. Instead we forbid indexation * Canonical URLs now use the official short URL (/w/, /w/p, /a, /c etc.)
This commit is contained in:
parent
e731f4b724
commit
f90db24233
23 changed files with 1876 additions and 1213 deletions
95
server/core/lib/html/client-html.ts
Normal file
95
server/core/lib/html/client-html.ts
Normal file
|
@ -0,0 +1,95 @@
|
|||
import { HttpStatusCode } from '@peertube/peertube-models'
|
||||
import express from 'express'
|
||||
import { logger } from '../../helpers/logger.js'
|
||||
import { ACCEPT_HEADERS } from '../../initializers/constants.js'
|
||||
import { VideoHtml } from './shared/video-html.js'
|
||||
import { PlaylistHtml } from './shared/playlist-html.js'
|
||||
import { ActorHtml } from './shared/actor-html.js'
|
||||
import { PageHtml } from './shared/page-html.js'
|
||||
|
||||
class ClientHtml {
|
||||
|
||||
static invalidateCache () {
|
||||
PageHtml.invalidateCache()
|
||||
}
|
||||
|
||||
static getDefaultHTMLPage (req: express.Request, res: express.Response, paramLang?: string) {
|
||||
return PageHtml.getDefaultHTML(req, res, paramLang)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static getWatchHTMLPage (videoIdArg: string, req: express.Request, res: express.Response) {
|
||||
return VideoHtml.getWatchVideoHTML(videoIdArg, req, res)
|
||||
}
|
||||
|
||||
static getVideoEmbedHTML (videoIdArg: string) {
|
||||
return VideoHtml.getEmbedVideoHTML(videoIdArg)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static getWatchPlaylistHTMLPage (videoPlaylistIdArg: string, req: express.Request, res: express.Response) {
|
||||
return PlaylistHtml.getWatchPlaylistHTML(videoPlaylistIdArg, req, res)
|
||||
}
|
||||
|
||||
static getVideoPlaylistEmbedHTML (playlistIdArg: string) {
|
||||
return PlaylistHtml.getEmbedPlaylistHTML(playlistIdArg)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
|
||||
return ActorHtml.getAccountHTMLPage(nameWithHost, req, res)
|
||||
}
|
||||
|
||||
static getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
|
||||
return ActorHtml.getVideoChannelHTMLPage(nameWithHost, req, res)
|
||||
}
|
||||
|
||||
static getActorHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
|
||||
return ActorHtml.getActorHTMLPage(nameWithHost, req, res)
|
||||
}
|
||||
}
|
||||
|
||||
function sendHTML (html: string, res: express.Response, localizedHTML: boolean = false) {
|
||||
res.set('Content-Type', 'text/html; charset=UTF-8')
|
||||
|
||||
if (localizedHTML) {
|
||||
res.set('Vary', 'Accept-Language')
|
||||
}
|
||||
|
||||
return res.send(html)
|
||||
}
|
||||
|
||||
async function serveIndexHTML (req: express.Request, res: express.Response) {
|
||||
if (req.accepts(ACCEPT_HEADERS) === 'html' || !req.headers.accept) {
|
||||
try {
|
||||
await generateHTMLPage(req, res, req.params.language)
|
||||
return
|
||||
} catch (err) {
|
||||
logger.error('Cannot generate HTML page.', { err })
|
||||
return res.status(HttpStatusCode.INTERNAL_SERVER_ERROR_500).end()
|
||||
}
|
||||
}
|
||||
|
||||
return res.status(HttpStatusCode.NOT_ACCEPTABLE_406).end()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
ClientHtml,
|
||||
sendHTML,
|
||||
serveIndexHTML
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Private
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) {
|
||||
const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang)
|
||||
|
||||
return sendHTML(html, res, true)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue