From 77fbea25af06f94eda2a8a95e052e5bcff12d444 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Wed, 8 Jun 2022 15:23:36 +0100 Subject: [PATCH] Allow for custom image logo (#642) * first test * add custom URL logo * some styling * fixed typo, wrong import * Update .env.example Co-authored-by: calle <93376500+callebtc@users.noreply.github.com> Co-authored-by: calle <93376500+callebtc@users.noreply.github.com> --- .env.example | 1 + lnbits/helpers.py | 6 ++++-- lnbits/settings.py | 6 +++--- lnbits/templates/base.html | 10 ++++++---- lnbits/templates/public.html | 12 +++++++++--- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 14a87d02..be818c4b 100644 --- a/.env.example +++ b/.env.example @@ -34,6 +34,7 @@ LNBITS_SITE_TAGLINE="free and open-source lightning wallet" LNBITS_SITE_DESCRIPTION="Some description about your service, will display if title is not 'LNbits'" # Choose from mint, flamingo, freedom, salvador, autumn, monochrome, classic LNBITS_THEME_OPTIONS="classic, bitcoin, freedom, mint, autumn, monochrome, salvador" +# LNBITS_CUSTOM_LOGO="https://lnbits.com/assets/images/logo/logo.svg" # Choose from LNPayWallet, OpenNodeWallet, LntxbotWallet, # LndRestWallet, CLightningWallet, LNbitsWallet, SparkWallet, FakeWallet, EclairWallet diff --git a/lnbits/helpers.py b/lnbits/helpers.py index cb6f8ee7..c0f37821 100644 --- a/lnbits/helpers.py +++ b/lnbits/helpers.py @@ -6,11 +6,10 @@ from typing import Any, List, NamedTuple, Optional import jinja2 import shortuuid # type: ignore +import lnbits.settings as settings from lnbits.jinja2_templating import Jinja2Templates from lnbits.requestvars import g -import lnbits.settings as settings - class Extension(NamedTuple): code: str @@ -160,6 +159,7 @@ def template_renderer(additional_folders: List = []) -> Jinja2Templates: ["lnbits/templates", "lnbits/core/templates", *additional_folders] ) ) + if settings.LNBITS_AD_SPACE: t.env.globals["AD_SPACE"] = settings.LNBITS_AD_SPACE t.env.globals["HIDE_API"] = settings.LNBITS_HIDE_API @@ -170,6 +170,8 @@ def template_renderer(additional_folders: List = []) -> Jinja2Templates: t.env.globals["LNBITS_THEME_OPTIONS"] = settings.LNBITS_THEME_OPTIONS t.env.globals["LNBITS_VERSION"] = settings.LNBITS_COMMIT t.env.globals["EXTENSIONS"] = get_valid_extensions() + if settings.LNBITS_CUSTOM_LOGO: + t.env.globals["USE_CUSTOM_LOGO"] = settings.LNBITS_CUSTOM_LOGO if settings.DEBUG: t.env.globals["VENDORED_JS"] = map(url_for_vendored, get_js_vendored()) diff --git a/lnbits/settings.py b/lnbits/settings.py index 9ccd9e4e..46b988fc 100644 --- a/lnbits/settings.py +++ b/lnbits/settings.py @@ -1,10 +1,9 @@ -import subprocess import importlib - -from environs import Env # type: ignore +import subprocess from os import path from typing import List +from environs import Env # type: ignore env = Env() env.read_env() @@ -47,6 +46,7 @@ LNBITS_THEME_OPTIONS: List[str] = env.list( default="classic, flamingo, mint, salvador, monochrome, autumn", subcast=str, ) +LNBITS_CUSTOM_LOGO = env.str("LNBITS_CUSTOM_LOGO", default="") WALLET = wallet_class() DEFAULT_WALLET_NAME = env.str("LNBITS_DEFAULT_WALLET_NAME", default="LNbits wallet") diff --git a/lnbits/templates/base.html b/lnbits/templates/base.html index d61a0ccf..758a746f 100644 --- a/lnbits/templates/base.html +++ b/lnbits/templates/base.html @@ -34,10 +34,12 @@ {% endblock %} - {% block toolbar_title %} {% if SITE_TITLE != 'LNbits' %} {{ - SITE_TITLE }} {% else %} LNbits {% endif %} {% - endblock %} + {% block toolbar_title %} {% if USE_CUSTOM_LOGO %} + Logo + {%else%} {% if SITE_TITLE != 'LNbits' %} {{ SITE_TITLE }} {% else + %} + LNbits {% endif %} {%endif%} {% endblock %} + {% block beta %} diff --git a/lnbits/templates/public.html b/lnbits/templates/public.html index d2f0e65a..a0dcbda8 100644 --- a/lnbits/templates/public.html +++ b/lnbits/templates/public.html @@ -1,7 +1,13 @@ {% extends "base.html" %} {% block beta %}{% endblock %} {% block drawer_toggle %}{% endblock %} {% block drawer %}{% endblock %} {% block toolbar_title %} - - {% if SITE_TITLE != 'LNbits' %} {{ SITE_TITLE }} {% else %} - LNbits {% endif %} + + {% if USE_CUSTOM_LOGO %} + Logo + {%else%} {% if SITE_TITLE != 'LNbits' %} {{ SITE_TITLE }} {% else %} + LNbits {% endif %} {% endif %} {% endblock %}