Add config option for theme directory for easier overrides of CSS/favicon.
This commit is contained in:
parent
6ebc8de311
commit
83cf8fc9cb
@ -193,6 +193,10 @@ class Config(dict):
|
|||||||
def cache_dir(self) -> str:
|
def cache_dir(self) -> str:
|
||||||
return os.path.abspath(str(self.get('cache_dir', '/tmp')))
|
return os.path.abspath(str(self.get('cache_dir', '/tmp')))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def theme(self) -> str:
|
||||||
|
return str(self.get('theme', 'default'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def event_log_duration(self) -> Optional[int]:
|
def event_log_duration(self) -> Optional[int]:
|
||||||
duration = self.get('event_log_duration')
|
duration = self.get('event_log_duration')
|
||||||
|
@ -235,15 +235,6 @@ def valid_pin(pin: str, type: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
|
||||||
def navigation() -> Dict[str, Any]:
|
|
||||||
# Look up JSX components we should provide for every page load
|
|
||||||
components = [
|
|
||||||
os.path.join('components', f)
|
|
||||||
for f in os.listdir(os.path.join(static_location, 'components'))
|
|
||||||
if re.search(r'\.react\.js$', f)
|
|
||||||
]
|
|
||||||
|
|
||||||
# Define useful functions for jnija2
|
# Define useful functions for jnija2
|
||||||
def jinja2_any(lval: Optional[List[Any]], pull: str, equals: str) -> bool:
|
def jinja2_any(lval: Optional[List[Any]], pull: str, equals: str) -> bool:
|
||||||
if lval is None:
|
if lval is None:
|
||||||
@ -253,6 +244,20 @@ def navigation() -> Dict[str, Any]:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def jinja2_theme(filename: str) -> str:
|
||||||
|
return url_for('static', filename=f"{config.theme}/{filename}")
|
||||||
|
|
||||||
|
|
||||||
|
@app.context_processor
|
||||||
|
def navigation() -> Dict[str, Any]:
|
||||||
|
# Look up JSX components we should provide for every page load
|
||||||
|
components = [
|
||||||
|
os.path.join('components', f)
|
||||||
|
for f in os.listdir(os.path.join(static_location, 'components'))
|
||||||
|
if re.search(r'\.react\.js$', f)
|
||||||
|
]
|
||||||
|
|
||||||
# Look up the logged in user ID.
|
# Look up the logged in user ID.
|
||||||
try:
|
try:
|
||||||
if g.userID is not None:
|
if g.userID is not None:
|
||||||
@ -262,6 +267,7 @@ def navigation() -> Dict[str, Any]:
|
|||||||
return {
|
return {
|
||||||
'components': components,
|
'components': components,
|
||||||
'any': jinja2_any,
|
'any': jinja2_any,
|
||||||
|
'theme_url': jinja2_theme,
|
||||||
}
|
}
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# If we are trying to render a 500 error and we couldn't even run the
|
# If we are trying to render a 500 error and we couldn't even run the
|
||||||
@ -270,6 +276,7 @@ def navigation() -> Dict[str, Any]:
|
|||||||
return {
|
return {
|
||||||
'components': components,
|
'components': components,
|
||||||
'any': jinja2_any,
|
'any': jinja2_any,
|
||||||
|
'theme_url': jinja2_theme,
|
||||||
}
|
}
|
||||||
|
|
||||||
pages: List[Dict[str, Any]] = []
|
pages: List[Dict[str, Any]] = []
|
||||||
@ -747,4 +754,5 @@ def navigation() -> Dict[str, Any]:
|
|||||||
'navigation': pages,
|
'navigation': pages,
|
||||||
'components': components,
|
'components': components,
|
||||||
'any': jinja2_any,
|
'any': jinja2_any,
|
||||||
|
'theme_url': jinja2_theme,
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
@ -3,12 +3,12 @@
|
|||||||
{% if title %}
|
{% if title %}
|
||||||
<title>{{ title }}</title>
|
<title>{{ title }}</title>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon.png') }}" />
|
<link rel="icon" type="image/png" href="{{ theme_url('favicon.png') }}" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='site.css') }}" />
|
<link rel="stylesheet" type="text/css" href="{{ theme_url('site.css') }}" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='color.css') }}" />
|
<link rel="stylesheet" type="text/css" href="{{ theme_url('color.css') }}" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='form.css') }}" />
|
<link rel="stylesheet" type="text/css" href="{{ theme_url('form.css') }}" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='section.css') }}" />
|
<link rel="stylesheet" type="text/css" href="{{ theme_url('section.css') }}" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='table.css') }}" />
|
<link rel="stylesheet" type="text/css" href="{{ theme_url('table.css') }}" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='jquery-confirm.css') }}" />
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='jquery-confirm.css') }}" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<script type="text/javascript" src="{{ url_for('static', filename='chart.bundle.min.js') }}"></script>
|
<script type="text/javascript" src="{{ url_for('static', filename='chart.bundle.min.js') }}"></script>
|
||||||
|
@ -76,3 +76,5 @@ cache_dir: '/tmp'
|
|||||||
# Number of seconds to preserve event logs before deleting them.
|
# Number of seconds to preserve event logs before deleting them.
|
||||||
# Set to zero or delete to disable deleting logs.
|
# Set to zero or delete to disable deleting logs.
|
||||||
event_log_duration: 2592000
|
event_log_duration: 2592000
|
||||||
|
# Frontend theme directory where sitewide CSS and favicon should be found.
|
||||||
|
theme: "default"
|
||||||
|
Loading…
Reference in New Issue
Block a user