diff options
| author | Marie <github@yuugi.dev> | 2025-04-12 00:11:55 +0000 |
|---|---|---|
| committer | Marie <github@yuugi.dev> | 2025-04-12 00:11:55 +0000 |
| commit | 7faef0d11e61d1b8206a6ed5139ab4a01ca63202 (patch) | |
| tree | f7048da0b9940946ba8f99bd90e82a668adbc3fa | |
| parent | merge: Fix SPDX-Header in two files (!958) (diff) | |
| parent | docs: Add usage example of "customHtml.head" to ".config/example.yml" (diff) | |
| download | sharkey-7faef0d11e61d1b8206a6ed5139ab4a01ca63202.tar.gz sharkey-7faef0d11e61d1b8206a6ed5139ab4a01ca63202.tar.bz2 sharkey-7faef0d11e61d1b8206a6ed5139ab4a01ca63202.zip | |
merge: feat: Allow injection of raw HTML strings inside <head> (!959)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/959
Closes #1029
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
| -rw-r--r-- | .config/example.yml | 8 | ||||
| -rw-r--r-- | packages/backend/src/config.ts | 12 | ||||
| -rw-r--r-- | packages/backend/src/server/web/ClientServerService.ts | 1 | ||||
| -rw-r--r-- | packages/backend/src/server/web/views/base.pug | 2 |
4 files changed, 23 insertions, 0 deletions
diff --git a/.config/example.yml b/.config/example.yml index f3caa0d676..08a5680c41 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -425,3 +425,11 @@ attachLdSignatureForRelays: true # If you're not using jemalloc, this may cause memory fragmentation and performance issues! (https://www.npmjs.com/package/ws#websocket-compression) # jemalloc is used by default in the Sharkey Docker image and may be set up manually otherwise: https://github.com/jemalloc/jemalloc/wiki/getting-started websocketCompression: false + +# Inject arbitrary HTML tags to customize Sharkey without having to fork it +#customHtml: +# head: | +# <!-- The possibilities are limitless! --> +# <script>console.log("Hello, world!")</script> +# <style>.whatever { color: red; }</style> +# <link rel="stylesheet" href="https://example.com/styles.css"> diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 067672fd79..9bbd50cac5 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -138,6 +138,10 @@ type Source = { }; websocketCompression?: boolean; + + customHtml?: { + head?: string; + } }; export type Config = { @@ -257,6 +261,10 @@ export type Config = { }; websocketCompression?: boolean; + + customHtml: { + head: string; + } }; export type FulltextSearchProvider = 'sqlLike' | 'sqlPgroonga' | 'meilisearch' | 'sqlTsvector'; @@ -406,6 +414,9 @@ export function loadConfig(): Config { maxAge: config.activityLogging?.maxAge ?? (1000 * 60 * 60 * 24 * 30), }, websocketCompression: config.websocketCompression ?? false, + customHtml: { + head: config.customHtml?.head ?? '', + }, }; } @@ -558,4 +569,5 @@ function applyEnvOverrides(config: Source) { _apply_top([['signToActivityPubGet', 'checkActivityPubGetSignature', 'setupPassword']]); _apply_top(['logging', 'sql', ['disableQueryTruncation', 'enableQueryParamLogging']]); _apply_top(['activityLogging', ['enabled', 'preSave', 'maxAge']]); + _apply_top(['customHtml', ['head']]); } diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts index 3ed811e737..437a6802b8 100644 --- a/packages/backend/src/server/web/ClientServerService.ts +++ b/packages/backend/src/server/web/ClientServerService.ts @@ -521,6 +521,7 @@ export class ClientServerService { url: this.config.url, title: this.meta.name ?? 'Sharkey', desc: this.meta.description, + customHead: this.config.customHtml.head, ...await this.generateCommonPugData(this.meta), ...data, }); diff --git a/packages/backend/src/server/web/views/base.pug b/packages/backend/src/server/web/views/base.pug index f57dbbbf4e..f7b0377b22 100644 --- a/packages/backend/src/server/web/views/base.pug +++ b/packages/backend/src/server/web/views/base.pug @@ -45,6 +45,8 @@ html link(rel='stylesheet' href=`/static-assets/fonts/sharkey-icons/style.css?version=${version}`) link(rel='modulepreload' href=`/vite/${entry.file}`) + | !{customHead} + if !config.frontendManifestExists script(type="module" src="/vite/@vite/client") |