From 1c1af489f1c276799a82814da5fc60288c74f1c0 Mon Sep 17 00:00:00 2001 From: Markos Gogoulos Date: Wed, 24 Sep 2025 16:26:45 +0300 Subject: [PATCH] feat: allow portal logo override (#1391) --- cms/settings.py | 10 ++++++++++ docs/admins_docs.md | 7 ++++++- files/context_processors.py | 6 ++++++ templates/config/installation/site.html | 10 +++++----- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cms/settings.py b/cms/settings.py index 10374063..1f9407c5 100644 --- a/cms/settings.py +++ b/cms/settings.py @@ -105,6 +105,16 @@ USE_L10N = True USE_TZ = True SITE_ID = 1 +# these are the logos by default. SVG gets a priority +# which means it will be used if available +# if you want to override them, set the new paths here +# and place the files on the static/images folder +PORTAL_LOGO_DARK_SVG = "/static/images/logo_dark.svg" +PORTAL_LOGO_DARK_PNG = "/static/images/logo_dark.png" +PORTAL_LOGO_LIGHT_SVG = "/static/images/logo_light.svg" +PORTAL_LOGO_LIGHT_PNG = "/static/images/logo_dark.png" + + # protection agains anonymous users # per ip address limit, for actions as like/dislike/report TIME_TO_ACTION_ANONYMOUS = 10 * 60 diff --git a/docs/admins_docs.md b/docs/admins_docs.md index c66b4cbc..a186ab40 100644 --- a/docs/admins_docs.md +++ b/docs/admins_docs.md @@ -240,7 +240,12 @@ Docker Compose installation: edit `deploy/docker/local_settings.py`, make a chan ### 5.1 Change portal logo -Set a new svg file for the white theme (`static/images/logo_dark.svg`) or the dark theme (`static/images/logo_light.svg`) +Find the default svg files for the white theme on `static/images/logo_dark.svg` and for the dark theme on `static/images/logo_light.svg` +You can specify new svg paths to override by editing the `PORTAL_LOGO_DARK_SVG` and `PORTAL_LOGO_LIGHT_SVG` variables in `settings.py`. + +You can also use custom pngs, by setting the variables `PORTAL_LOGO_DARK_PNG` and `PORTAL_LOGO_LIGHT_PNG` in `settings.py`. The svg files have priority over png files, so if both are set, svg files will be used. + +In any case, make sure the files are placed on the static/images folder. ### 5.2 Set global portal title diff --git a/files/context_processors.py b/files/context_processors.py index fcd0be89..585d656d 100644 --- a/files/context_processors.py +++ b/files/context_processors.py @@ -12,6 +12,12 @@ def stuff(request): ret["FRONTEND_HOST"] = request.build_absolute_uri('/').rstrip('/') ret["DEFAULT_THEME"] = settings.DEFAULT_THEME ret["PORTAL_NAME"] = settings.PORTAL_NAME + + ret["PORTAL_LOGO_DARK_SVG"] = settings.PORTAL_LOGO_DARK_SVG + ret["PORTAL_LOGO_DARK_PNG"] = settings.PORTAL_LOGO_DARK_PNG + ret["PORTAL_LOGO_LIGHT_SVG"] = settings.PORTAL_LOGO_LIGHT_SVG + ret["PORTAL_LOGO_LIGHT_PNG"] = settings.PORTAL_LOGO_LIGHT_PNG + ret["PORTAL_DESCRIPTION"] = settings.PORTAL_DESCRIPTION ret["LOAD_FROM_CDN"] = settings.LOAD_FROM_CDN ret["CAN_LOGIN"] = settings.LOGIN_ALLOWED diff --git a/templates/config/installation/site.html b/templates/config/installation/site.html index 80cbf8c5..c3aa7777 100644 --- a/templates/config/installation/site.html +++ b/templates/config/installation/site.html @@ -4,19 +4,19 @@ MediaCMS.site = { url: '{{FRONTEND_HOST}}', api: '{{FRONTEND_HOST}}/api/v1', theme: { - mode: '{{DEFAULT_THEME}}', + mode: '{{DEFAULT_THEME}}', switch: { position: 'sidebar', // Valid values: 'header', 'sidebar'. }, }, logo:{ lightMode:{ - img: "/static/images/logo_dark.png", - svg: "/static/images/logo_dark.svg", + img: "{{PORTAL_LOGO_DARK_PNG}}", + svg: "{{PORTAL_LOGO_DARK_SVG}}", }, darkMode:{ - img: "/static/images/logo_light.png", - svg: "/static/images/logo_light.svg", + img: "{{PORTAL_LOGO_LIGHT_PNG}}", + svg: "{{PORTAL_LOGO_LIGHT_SVG}}", }, }, pages: {