mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Add instance avatar to default open graph tags
This commit is contained in:
parent
5af6cf6e82
commit
54adc6f038
14 changed files with 119 additions and 49 deletions
|
@ -84,9 +84,7 @@ export class ActorHtml {
|
|||
updatedAt: entity.updatedAt
|
||||
},
|
||||
|
||||
indexationPolicy: entity.Actor.isOwned()
|
||||
? 'always'
|
||||
: 'never'
|
||||
forbidIndexation: !entity.Actor.isOwned()
|
||||
}, {})
|
||||
|
||||
return customHTML
|
||||
|
|
|
@ -14,6 +14,6 @@ export class CommonEmbedHtml {
|
|||
let htmlResult = TagsHtml.addTitleTag(html)
|
||||
htmlResult = TagsHtml.addDescriptionTag(htmlResult)
|
||||
|
||||
return TagsHtml.addTags(htmlResult, { indexationPolicy: 'never' }, { playlist, video })
|
||||
return TagsHtml.addTags(htmlResult, { forbidIndexation: true }, { playlist, video })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '@peertube/peertube-core-utils'
|
||||
import { buildFileLocale, escapeHTML, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '@peertube/peertube-core-utils'
|
||||
import { ActorImageType, HTMLServerConfig } from '@peertube/peertube-models'
|
||||
import { isTestOrDevInstance, root, sha256 } from '@peertube/peertube-node-utils'
|
||||
import { CONFIG } from '@server/initializers/config.js'
|
||||
import { ActorImageModel } from '@server/models/actor/actor-image.js'
|
||||
import { getServerActor } from '@server/models/application/application.js'
|
||||
import express from 'express'
|
||||
import { pathExists } from 'fs-extra/esm'
|
||||
import { readFile } from 'fs/promises'
|
||||
import { join } from 'path'
|
||||
import { logger } from '../../../helpers/logger.js'
|
||||
import { CUSTOM_HTML_TAG_COMMENTS, FILES_CONTENT_HASH, PLUGIN_GLOBAL_CSS_PATH } from '../../../initializers/constants.js'
|
||||
import { CUSTOM_HTML_TAG_COMMENTS, FILES_CONTENT_HASH, PLUGIN_GLOBAL_CSS_PATH, WEBSERVER } from '../../../initializers/constants.js'
|
||||
import { ServerConfigManager } from '../../server-config-manager.js'
|
||||
import { TagsHtml } from './tags-html.js'
|
||||
import { pathExists } from 'fs-extra/esm'
|
||||
import { HTMLServerConfig } from '@peertube/peertube-models'
|
||||
import { CONFIG } from '@server/initializers/config.js'
|
||||
|
||||
export class PageHtml {
|
||||
|
||||
|
@ -22,13 +24,33 @@ export class PageHtml {
|
|||
}
|
||||
|
||||
static async getDefaultHTML (req: express.Request, res: express.Response, paramLang?: string) {
|
||||
const html = paramLang
|
||||
? await this.getIndexHTML(req, res, paramLang)
|
||||
: await this.getIndexHTML(req, res)
|
||||
const html = await this.getIndexHTML(req, res, paramLang)
|
||||
const serverActor = await getServerActor()
|
||||
const avatar = serverActor.getMaxQualityImage(ActorImageType.AVATAR)
|
||||
|
||||
let customHTML = TagsHtml.addTitleTag(html)
|
||||
customHTML = TagsHtml.addDescriptionTag(customHTML)
|
||||
|
||||
const url = req.originalUrl === '/'
|
||||
? WEBSERVER.URL
|
||||
: WEBSERVER.URL + req.originalUrl
|
||||
|
||||
customHTML = await TagsHtml.addTags(customHTML, {
|
||||
url,
|
||||
|
||||
escapedSiteName: escapeHTML(CONFIG.INSTANCE.NAME),
|
||||
escapedTitle: escapeHTML(CONFIG.INSTANCE.NAME),
|
||||
escapedTruncatedDescription: escapeHTML(CONFIG.INSTANCE.SHORT_DESCRIPTION),
|
||||
|
||||
image: avatar
|
||||
? { url: ActorImageModel.getImageUrl(avatar), width: avatar.width, height: avatar.height }
|
||||
: undefined,
|
||||
|
||||
ogType: 'website',
|
||||
twitterCard: 'summary_large_image',
|
||||
forbidIndexation: false
|
||||
}, {})
|
||||
|
||||
return customHTML
|
||||
}
|
||||
|
||||
|
|
|
@ -113,11 +113,11 @@ export class PlaylistHtml {
|
|||
escapedTitle: escapeHTML(playlist.name),
|
||||
escapedTruncatedDescription,
|
||||
|
||||
indexationPolicy: !playlist.isOwned() || playlist.privacy !== VideoPlaylistPrivacy.PUBLIC
|
||||
? 'never'
|
||||
: 'always',
|
||||
forbidIndexation: !playlist.isOwned() || playlist.privacy !== VideoPlaylistPrivacy.PUBLIC,
|
||||
|
||||
image: { url: playlist.getThumbnailUrl() },
|
||||
image: playlist.Thumbnail
|
||||
? { url: playlist.getThumbnailUrl(), width: playlist.Thumbnail.width, height: playlist.Thumbnail.height }
|
||||
: undefined,
|
||||
|
||||
list,
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import truncate from 'lodash-es/truncate.js'
|
|||
import { mdToOneLinePlainText } from '@server/helpers/markdown.js'
|
||||
|
||||
type Tags = {
|
||||
indexationPolicy: 'always' | 'never'
|
||||
forbidIndexation: boolean
|
||||
|
||||
url?: string
|
||||
|
||||
|
@ -31,8 +31,8 @@ type Tags = {
|
|||
|
||||
image?: {
|
||||
url: string
|
||||
width?: number
|
||||
height?: number
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
|
||||
embed?: {
|
||||
|
@ -76,7 +76,7 @@ export class TagsHtml {
|
|||
const twitterCardMetaTags = this.generateTwitterCardMetaTagsOptions(tagsValues)
|
||||
const schemaTags = await this.generateSchemaTagsOptions(tagsValues, context)
|
||||
|
||||
const { url, escapedTitle, oembedUrl, indexationPolicy } = tagsValues
|
||||
const { url, escapedTitle, oembedUrl, forbidIndexation } = tagsValues
|
||||
|
||||
const oembedLinkTags: { type: string, href: string, escapedTitle: string }[] = []
|
||||
|
||||
|
@ -126,11 +126,11 @@ export class TagsHtml {
|
|||
}
|
||||
|
||||
// SEO, use origin URL
|
||||
if (indexationPolicy !== 'never' && url) {
|
||||
if (forbidIndexation === true && url) {
|
||||
tagsStr += `<link rel="canonical" href="${url}" />`
|
||||
}
|
||||
|
||||
if (indexationPolicy === 'never') {
|
||||
if (forbidIndexation === true) {
|
||||
tagsStr += `<meta name="robots" content="noindex" />`
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import validator from 'validator'
|
|||
import { CONFIG } from '../../../initializers/config.js'
|
||||
import { MEMOIZE_TTL, WEBSERVER } from '../../../initializers/constants.js'
|
||||
import { VideoModel } from '../../../models/video/video.js'
|
||||
import { MVideo, MVideoThumbnailBlacklist } from '../../../types/models/index.js'
|
||||
import { MVideo, MVideoThumbnail, MVideoThumbnailBlacklist } from '../../../types/models/index.js'
|
||||
import { getActivityStreamDuration } from '../../activitypub/activity.js'
|
||||
import { isVideoInPrivateDirectory } from '../../video-privacy.js'
|
||||
import { CommonEmbedHtml } from './common-embed-html.js'
|
||||
|
@ -78,7 +78,7 @@ export class VideoHtml {
|
|||
|
||||
private static buildVideoHTML (options: {
|
||||
html: string
|
||||
video: MVideo
|
||||
video: MVideoThumbnail
|
||||
|
||||
addOG: boolean
|
||||
addTwitterCard: boolean
|
||||
|
@ -111,6 +111,8 @@ export class VideoHtml {
|
|||
|
||||
const schemaType = 'VideoObject'
|
||||
|
||||
const preview = video.getPreview()
|
||||
|
||||
return TagsHtml.addTags(customHTML, {
|
||||
url: WEBSERVER.URL + video.getWatchStaticPath(),
|
||||
|
||||
|
@ -118,11 +120,11 @@ export class VideoHtml {
|
|||
escapedTitle: escapeHTML(video.name),
|
||||
escapedTruncatedDescription,
|
||||
|
||||
indexationPolicy: video.remote || video.privacy !== VideoPrivacy.PUBLIC
|
||||
? 'never'
|
||||
: 'always',
|
||||
forbidIndexation: video.remote || video.privacy !== VideoPrivacy.PUBLIC,
|
||||
|
||||
image: { url: WEBSERVER.URL + video.getPreviewStaticPath() },
|
||||
image: preview
|
||||
? { url: WEBSERVER.URL + video.getPreviewStaticPath(), width: preview.width, height: preview.height }
|
||||
: undefined,
|
||||
|
||||
embed,
|
||||
oembedUrl: this.getOEmbedUrl(video, currentQuery),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue