From e5aa247f11665b40e2ac0d7c117b3517c5a3b27d Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 16 Sep 2022 19:26:16 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20icons=20+=20style=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets.py | 5 +++++ src/config.py | 29 +++++++++++++++++++++++++++++ src/fn.py | 8 ++++++++ src/html_fn.py | 40 +++++++++++++++++++++++++++++----------- src/index.py | 8 ++++---- src/msg.py | 4 ++++ src/notification.py | 4 ++++ 7 files changed, 83 insertions(+), 15 deletions(-) diff --git a/src/assets.py b/src/assets.py index cb9f373..96e1956 100644 --- a/src/assets.py +++ b/src/assets.py @@ -5,6 +5,10 @@ import os asset_pages = Blueprint("assets", __name__) +################### +### Site Assets ### +################### + def filesend(path): filename = os.path.basename(path) @@ -18,6 +22,7 @@ def me_picture(): return filesend("/config/me.avif") +# Background Image @asset_pages.route("/wall") def wall_bg(): return filesend("/config/wall.avif") diff --git a/src/config.py b/src/config.py index 92048fc..a84239f 100644 --- a/src/config.py +++ b/src/config.py @@ -1,10 +1,39 @@ import json +##################### +### Configuration ### +##################### + CONFIG = json.loads(open("/config/config.json").read()) +# Colors Array def colors(): try: return json.loads(open("/config/colors.json").read()) except: return None + + +# Foreground Color +def fg_color(): + if colors() is not None: + fg = colors()["special"]["foreground"] + if "colors" in CONFIG: + if "fg" in CONFIG["colors"]: + i = CONFIG["colors"]["fg"] - 1 + fg = colors()["colors"][f"color{i}"] + return fg + return None + + +# Background Color +def bg_color(): + if colors() is not None: + bg = colors()["special"]["background"] + if "colors" in CONFIG: + if "bg" in CONFIG["colors"]: + i = CONFIG["colors"]["bg"] - 1 + bg = colors()["colors"][f"color{i}"] + return bg + return None diff --git a/src/fn.py b/src/fn.py index bdacad1..b090723 100644 --- a/src/fn.py +++ b/src/fn.py @@ -1,15 +1,22 @@ import flask from htmlpy import Link +###################### +### Site Functions ### +###################### + +# Check if request is from onion def is_onion(req: flask.globals.request) -> bool: return req.host.endswith("onion") +# Check if request is from i2p def is_i2p(req: flask.globals.request) -> bool: return req.host.endswith("i2p") +# Return dynamic link depending on request origin def dynamic_link( inner, normal: str, onion: str, i2p: str, req: flask.globals.request ) -> Link: @@ -20,6 +27,7 @@ def dynamic_link( return Link(normal, inner) +# Check if request is from common browsers def is_browser(req: flask.globals.request) -> bool: ua = req.user_agent.string.lower() if "chrome" in ua or "safari" in ua or "firefox" in ua: diff --git a/src/html_fn.py b/src/html_fn.py index ef3cf08..7ec6ff6 100644 --- a/src/html_fn.py +++ b/src/html_fn.py @@ -1,25 +1,34 @@ import requests import os from htmlpy import * -from config import colors, CONFIG +from config import colors, CONFIG, fg_color, bg_color + +############################ +### HTML Generation Code ### +############################ + +# Bootstrap Icon +def Icon(code, middle_align=False): + style = "" + if middle_align: + style = "vertical-align: middle;" + return Span( + "", global_attr=GlobalAttributes(css_class=f"bi bi-{code}", style=style) + ) + # Wrapper for Base HTML def buildSite(content, title=None, disable_color=False, shadow=True): c_class = "bg-dark text-white justify-content-center text-center" c_style = "" + g_style = "a {text-decoration: none; font-weight: bold; color: white}" if not disable_color: if colors() is not None: c_class = "justify-content-center text-center" - fg = colors()["special"]["foreground"] - bg = colors()["special"]["background"] - if "colors" in CONFIG: - if "fg" in CONFIG["colors"]: - i = CONFIG["colors"]["fg"] - 1 - fg = colors()["colors"][f"color{i}"] - if "bg" in CONFIG["colors"]: - i = CONFIG["colors"]["bg"] - 1 - bg = colors()["colors"][f"color{i}"] + fg = fg_color() + bg = bg_color() c_style = f"background: {bg}; color: {fg};" + g_style = f"a {{text-decoration: none; font-weight: bold; color: {fg}}}" if os.path.exists("/config/wall.avif"): c_style += "background-image: url('assets/wall');background-size:cover;" @@ -39,7 +48,7 @@ def buildSite(content, title=None, disable_color=False, shadow=True): ] ), body=Body( - content, + [Style(g_style), content], global_attr=GlobalAttributes(css_class=c_class, style=c_style), ), ) @@ -65,6 +74,15 @@ def cache_bootstrap(): "https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js", "/app/static/bootstrap.bundle.min.js", ) + os.makedirs("/app/static/fonts", exist_ok=True) + download_file( + "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/fonts/bootstrap-icons.woff2?8d200481aa7f02a2d63a331fc782cfaf", + "/app/static/fonts/bootstrap-icons.woff2", + ) + download_file( + "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/fonts/bootstrap-icons.woff?8d200481aa7f02a2d63a331fc782cfaf", + "/app/static/fonts/bootstrap-icons.woff", + ) # Bootstrap CSS diff --git a/src/index.py b/src/index.py index 9cddff5..2cf95f3 100644 --- a/src/index.py +++ b/src/index.py @@ -4,8 +4,8 @@ import gnupg from flask import request, Blueprint, Response, redirect from htmlpy import * -from config import CONFIG, colors -from html_fn import buildSite +from config import CONFIG, colors, fg_color, bg_color +from html_fn import buildSite, Icon from msg import encrypt, save_message from notification import notify from fn import is_browser @@ -189,7 +189,7 @@ def public_key(): def build_contact_block(): return Div( [ - Heading(1, "Contact"), + Heading(1, [Icon("person-lines-fill"), "Contact"]), ThematicBreak(), [ Link("/public_key", "My PGP Key"), @@ -211,7 +211,7 @@ def build_contact_block(): def build_donation_block(): return Div( [ - Heading(1, "Donation"), + Heading(1, [Icon("cash-coin", True), "Donation"]), ThematicBreak(), Paragraph( [ diff --git a/src/msg.py b/src/msg.py index e9eabed..0ebcf2d 100644 --- a/src/msg.py +++ b/src/msg.py @@ -2,6 +2,10 @@ import datetime import os import gnupg +################ +### Messages ### +################ + # Encrypt msg with GPG def encrypt(msg): pgp = gnupg.GPG() diff --git a/src/notification.py b/src/notification.py index 03b06a5..b3bbe30 100644 --- a/src/notification.py +++ b/src/notification.py @@ -1,6 +1,10 @@ from config import CONFIG import requests +##################### +### Notifications ### +##################### + # Send Notification to all handlers def notify(msg, title=None): try: