X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fclient-html.ts;h=81b3fff027d6ec28bbc83eebe4dd299c8187fcb3;hb=d91ce83d392801fd592adeb08a7674b4017ffe82;hp=4fd9a4263d665fcf1d58b398dad6cfa05022a581;hpb=80d7d180a368dc966bba383f3117ed131f5e0d42;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 4fd9a4263..81b3fff02 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -27,9 +27,10 @@ import { AccountModel } from '../models/account/account' import { VideoModel } from '../models/video/video' import { VideoChannelModel } from '../models/video/video-channel' import { VideoPlaylistModel } from '../models/video/video-playlist' -import { MAccountActor, MChannelActor } from '../types/models' +import { MAccountActor, MChannelActor, MVideo, MVideoPlaylist } from '../types/models' import { getActivityStreamDuration } from './activitypub/activity' import { getBiggestActorImage } from './actor-image' +import { Hooks } from './plugins/hooks' import { ServerConfigManager } from './server-config-manager' type Tags = { @@ -64,6 +65,11 @@ type Tags = { } } +type HookContext = { + video?: MVideo + playlist?: MVideoPlaylist +} + class ClientHtml { private static htmlCache: { [path: string]: string } = {} @@ -129,7 +135,7 @@ class ClientHtml { const twitterCard = CONFIG.SERVICES.TWITTER.WHITELISTED ? 'player' : 'summary_large_image' const schemaType = 'VideoObject' - customHtml = ClientHtml.addTags(customHtml, { + customHtml = await ClientHtml.addTags(customHtml, { url, originUrl, escapedSiteName: escapeHTML(siteName), @@ -141,7 +147,7 @@ class ClientHtml { ogType, twitterCard, schemaType - }) + }, { video }) return customHtml } @@ -193,7 +199,7 @@ class ClientHtml { const twitterCard = CONFIG.SERVICES.TWITTER.WHITELISTED ? 'player' : 'summary' const schemaType = 'ItemList' - customHtml = ClientHtml.addTags(customHtml, { + customHtml = await ClientHtml.addTags(customHtml, { url, originUrl, escapedSiteName: escapeHTML(siteName), @@ -206,7 +212,7 @@ class ClientHtml { ogType, twitterCard, schemaType - }) + }, { playlist: videoPlaylist }) return customHtml } @@ -290,7 +296,7 @@ class ClientHtml { const twitterCard = 'summary' const schemaType = 'ProfilePage' - customHtml = ClientHtml.addTags(customHtml, { + customHtml = await ClientHtml.addTags(customHtml, { url, originUrl, escapedTitle: escapeHTML(title), @@ -301,7 +307,7 @@ class ClientHtml { twitterCard, schemaType, disallowIndexation: !entity.Actor.isOwned() - }) + }, {}) return customHtml } @@ -469,7 +475,7 @@ class ClientHtml { return metaTags } - private static generateSchemaTags (tags: Tags) { + private static async generateSchemaTags (tags: Tags, context: HookContext) { const schema = { '@context': 'http://schema.org', '@type': tags.schemaType, @@ -495,14 +501,14 @@ class ClientHtml { schema['contentUrl'] = tags.url } - return schema + return Hooks.wrapObject(schema, 'filter:html.client.json-ld.result', context) } - private static addTags (htmlStringPage: string, tagsValues: Tags) { + private static async addTags (htmlStringPage: string, tagsValues: Tags, context: HookContext) { const openGraphMetaTags = this.generateOpenGraphMetaTags(tagsValues) const standardMetaTags = this.generateStandardMetaTags(tagsValues) const twitterCardMetaTags = this.generateTwitterCardMetaTags(tagsValues) - const schemaTags = this.generateSchemaTags(tagsValues) + const schemaTags = await this.generateSchemaTags(tagsValues, context) const { url, escapedTitle, embed, originUrl, disallowIndexation } = tagsValues