1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

Add ability to customize instance logo

This commit is contained in:
Chocobozzz 2025-06-19 14:25:54 +02:00
parent f5fd593976
commit c0f4de6077
No known key found for this signature in database
GPG key ID: 583A612D890159BE
96 changed files with 1910 additions and 532 deletions

View file

@ -4,7 +4,7 @@ import { WEBSERVER } from '@server/initializers/constants.js'
import { AccountModel } from '@server/models/account/account.js'
import { ActorImageModel } from '@server/models/actor/actor-image.js'
import { VideoChannelModel } from '@server/models/video/video-channel.js'
import { MAccountHost, MChannelHost } from '@server/types/models/index.js'
import { MAccountDefault, MChannelDefault } from '@server/types/models/index.js'
import express from 'express'
import { CONFIG } from '../../../initializers/config.js'
import { PageHtml } from './page-html.js'
@ -55,8 +55,8 @@ export class ActorHtml {
// ---------------------------------------------------------------------------
private static async getAccountOrChannelHTMLPage (options: {
loader: () => Promise<MAccountHost | MChannelHost>
getRSSFeeds: (entity: MAccountHost | MChannelHost) => TagsOptions['rssFeeds']
loader: () => Promise<MAccountDefault | MChannelDefault>
getRSSFeeds: (entity: MAccountDefault | MChannelDefault) => TagsOptions['rssFeeds']
req: express.Request
res: express.Response
}) {

View file

@ -6,10 +6,9 @@ import {
is18nLocale,
POSSIBLE_LOCALES
} from '@peertube/peertube-core-utils'
import { ActorImageType, HTMLServerConfig } from '@peertube/peertube-models'
import { 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'
@ -32,7 +31,8 @@ export class PageHtml {
static async getDefaultHTML (req: express.Request, res: express.Response, paramLang?: string) {
const html = await this.getIndexHTML(req, res, paramLang)
const serverActor = await getServerActor()
const avatar = serverActor.getMaxQualityImage(ActorImageType.AVATAR)
const openGraphImage = ServerConfigManager.Instance.getDefaultOpenGraph(serverActor)
let customHTML = TagsHtml.addTitleTag(html)
customHTML = TagsHtml.addDescriptionTag(customHTML)
@ -52,8 +52,8 @@ export class PageHtml {
? TagsHtml.findRelMe(CONFIG.INSTANCE.DESCRIPTION)
: undefined,
image: avatar
? { url: ActorImageModel.getImageUrl(avatar), width: avatar.width, height: avatar.height }
image: openGraphImage
? { url: openGraphImage.fileUrl, width: openGraphImage.width, height: openGraphImage.height }
: undefined,
ogType: 'website',
@ -99,8 +99,6 @@ export class PageHtml {
let html = buffer.toString()
html = this.addManifestContentHash(html)
html = this.addFaviconContentHash(html)
html = this.addLogoContentHash(html)
html = this.addCustomCSS(html)
html = this.addServerConfig(html, serverConfig)
@ -189,12 +187,4 @@ export class PageHtml {
private static addManifestContentHash (htmlStringPage: string) {
return htmlStringPage.replace('[manifestContentHash]', FILES_CONTENT_HASH.MANIFEST)
}
private static addFaviconContentHash (htmlStringPage: string) {
return htmlStringPage.replace('[faviconContentHash]', FILES_CONTENT_HASH.FAVICON)
}
private static addLogoContentHash (htmlStringPage: string) {
return htmlStringPage.replace('[logoContentHash]', FILES_CONTENT_HASH.LOGO)
}
}

View file

@ -1,5 +1,7 @@
import { escapeAttribute, escapeHTML } from '@peertube/peertube-core-utils'
import { escapeAttribute, escapeHTML, findAppropriateImage } from '@peertube/peertube-core-utils'
import { mdToPlainText } from '@server/helpers/markdown.js'
import { ServerConfigManager } from '@server/lib/server-config-manager.js'
import { getServerActor } from '@server/models/application/application.js'
import truncate from 'lodash-es/truncate.js'
import { parse } from 'node-html-parser'
import { CONFIG } from '../../../initializers/config.js'
@ -87,26 +89,17 @@ export class TagsHtml {
// ---------------------------------------------------------------------------
static async addTags (htmlStringPage: string, tagsValues: TagsOptions, context: HookContext) {
const { url, escapedTitle, oembedUrl, forbidIndexation, embedIndexation, relMe, rssFeeds } = tagsValues
const serverActor = await getServerActor()
let tagsStr = ''
// Global meta tags
const metaTags = {
...this.generateOpenGraphMetaTagsOptions(tagsValues),
...this.generateStandardMetaTagsOptions(tagsValues),
...this.generateTwitterCardMetaTagsOptions(tagsValues)
}
const schemaTags = await this.generateSchemaTagsOptions(tagsValues, context)
const { url, escapedTitle, oembedUrl, forbidIndexation, embedIndexation, relMe, rssFeeds } = tagsValues
const oembedLinkTags: { type: string, href: string, escapedTitle: string }[] = []
if (oembedUrl) {
oembedLinkTags.push({
type: 'application/json+oembed',
href: WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(oembedUrl),
escapedTitle
})
}
let tagsStr = ''
for (const tagName of Object.keys(metaTags)) {
const tagValue = metaTags[tagName]
@ -116,23 +109,27 @@ export class TagsHtml {
}
// OEmbed
for (const oembedLinkTag of oembedLinkTags) {
tagsStr += `<link rel="alternate" type="${oembedLinkTag.type}" href="${oembedLinkTag.href}" title="${
escapeAttribute(oembedLinkTag.escapedTitle)
}" />`
if (oembedUrl) {
const href = WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(oembedUrl)
tagsStr += `<link rel="alternate" type="application/json+oembed" href="${href}" title="${escapeAttribute(escapedTitle)}" />`
}
// Schema.org
const schemaTags = await this.generateSchemaTagsOptions(tagsValues, context)
if (schemaTags) {
tagsStr += `<script type="application/ld+json">${JSON.stringify(schemaTags)}</script>`
}
// Rel Me
if (Array.isArray(relMe)) {
for (const relMeLink of relMe) {
tagsStr += `<link href="${escapeAttribute(relMeLink)}" rel="me">`
}
}
// SEO
if (forbidIndexation === true) {
tagsStr += `<meta name="robots" content="noindex" />`
} else if (embedIndexation) {
@ -141,10 +138,23 @@ export class TagsHtml {
tagsStr += `<link rel="canonical" href="${url}" />`
}
// RSS
for (const rssLink of (rssFeeds || [])) {
tagsStr += `<link rel="alternate" type="application/rss+xml" title="${escapeAttribute(rssLink.title)}" href="${rssLink.url}" />`
}
// Favicon
const favicon = ServerConfigManager.Instance.getFavicon(serverActor)
tagsStr += `<link rel="icon" type="image/png" href="${escapeAttribute(favicon.fileUrl)}" />`
// Apple Touch Icon
const appleTouchIcon = findAppropriateImage(serverActor.Avatars, 192)
const iconHref = appleTouchIcon
? WEBSERVER.URL + appleTouchIcon.getStaticPath()
: '/client/assets/images/icons/icon-192x192.png'
tagsStr += `<link rel="apple-touch-icon" href="${iconHref}" />`
return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.META_TAGS, tagsStr)
}