diff --git a/plinth/context_processors.py b/plinth/context_processors.py
index c1028758c..1518afa78 100644
--- a/plinth/context_processors.py
+++ b/plinth/context_processors.py
@@ -8,7 +8,7 @@ import re
from django.utils.translation import gettext as _
from django.utils.translation import gettext_noop
-from plinth import cfg
+from plinth import cfg, web_server
from plinth.utils import is_user_admin
@@ -35,6 +35,7 @@ def common(request):
'active_menu_urls': active_menu_urls,
'box_name': _(cfg.box_name),
'user_is_admin': is_user_admin(request, True),
+ 'user_css': web_server.get_user_css(),
'notifications': notifications_context['notifications'],
'notifications_max_severity': notifications_context['max_severity']
}
diff --git a/plinth/templates/base.html b/plinth/templates/base.html
index e3897abb4..c2f5c6215 100644
--- a/plinth/templates/base.html
+++ b/plinth/templates/base.html
@@ -50,10 +50,14 @@
-
+
+ {% if user_css %}
+
+ {% endif %}
+
diff --git a/plinth/web_server.py b/plinth/web_server.py
index 6b6317598..9020c8be4 100644
--- a/plinth/web_server.py
+++ b/plinth/web_server.py
@@ -5,6 +5,7 @@ Setup CherryPy web server.
import logging
import os
+import pathlib
import sys
import warnings
from typing import ClassVar
@@ -27,6 +28,24 @@ MODULES_EXCLUDED_FROM_AUTORELOAD = [
'psycopg2',
]
+_CUSTOM_STATIC_URL = '/custom/static'
+
+_USER_CSS_PATH = 'css/user.css'
+
+
+def get_custom_static_url():
+ """Return the URL path fragment for custom static URL."""
+ return f'{cfg.server_dir}{_CUSTOM_STATIC_URL}'
+
+
+def get_user_css():
+ """Return the URL path fragement for user CSS if it exists else None."""
+ user_css_path = pathlib.Path(cfg.custom_static_dir) / _USER_CSS_PATH
+ if not user_css_path.exists():
+ return None
+
+ return get_custom_static_url() + '/' + _USER_CSS_PATH
+
def _mount_static_directory(static_dir, static_url):
config = {
@@ -64,7 +83,7 @@ def init():
_mount_static_directory(static_dir, web_framework.get_static_url())
custom_static_dir = cfg.custom_static_dir
- custom_static_url = '/plinth/custom/static'
+ custom_static_url = get_custom_static_url()
if os.path.exists(custom_static_dir):
_mount_static_directory(custom_static_dir, custom_static_url)
else: