From caf2aaf4f9d38ad441a5562c3b8720f8779d6f78 Mon Sep 17 00:00:00 2001 From: Kim <1877318+kimsible@users.noreply.github.com> Date: Fri, 10 Jul 2020 10:20:11 +0200 Subject: Add ability to override client assets : logo - favicon - PWA icons - PWA manifest name and description (#2897) * Add client-overrides storage to config * Add static-serve for client overrides * Move backgroun-image logo from bundle to css tag for runtime content hash * Add dynamic JSON manifest * Add content hash for manifest, favicon and logo Co-authored-by: kimsible --- server/lib/client-html.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'server/lib/client-html.ts') diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 3e6da2898..5996f3c70 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n' -import { CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE, PLUGIN_GLOBAL_CSS_PATH, WEBSERVER } from '../initializers/constants' +import { CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE, PLUGIN_GLOBAL_CSS_PATH, WEBSERVER, FILES_CONTENT_HASH } from '../initializers/constants' import { join } from 'path' import { escapeHTML, sha256 } from '../helpers/core-utils' import { VideoModel } from '../models/video/video' @@ -101,6 +101,9 @@ export class ClientHtml { let html = buffer.toString() if (paramLang) html = ClientHtml.addHtmlLang(html, paramLang) + html = ClientHtml.addManifestContentHash(html) + html = ClientHtml.addFaviconContentHash(html) + html = ClientHtml.addLogoContentHash(html) html = ClientHtml.addCustomCSS(html) html = await ClientHtml.addAsyncPluginCSS(html) @@ -136,6 +139,18 @@ export class ClientHtml { return htmlStringPage.replace('', ``) } + 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) + } + private static addTitleTag (htmlStringPage: string, title?: string) { let text = title || CONFIG.INSTANCE.NAME if (title) text += ` - ${CONFIG.INSTANCE.NAME}` -- cgit v1.2.3