icons + style changes

This commit is contained in:
JMARyA 2022-09-16 19:26:16 +02:00
parent 37800adce4
commit e5aa247f11
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
7 changed files with 83 additions and 15 deletions

View file

@ -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")

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -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(
[

View file

@ -2,6 +2,10 @@ import datetime
import os
import gnupg
################
### Messages ###
################
# Encrypt msg with GPG
def encrypt(msg):
pgp = gnupg.GPG()

View file

@ -1,6 +1,10 @@
from config import CONFIG
import requests
#####################
### Notifications ###
#####################
# Send Notification to all handlers
def notify(msg, title=None):
try: