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__) asset_pages = Blueprint("assets", __name__)
###################
### Site Assets ###
###################
def filesend(path): def filesend(path):
filename = os.path.basename(path) filename = os.path.basename(path)
@ -18,6 +22,7 @@ def me_picture():
return filesend("/config/me.avif") return filesend("/config/me.avif")
# Background Image
@asset_pages.route("/wall") @asset_pages.route("/wall")
def wall_bg(): def wall_bg():
return filesend("/config/wall.avif") return filesend("/config/wall.avif")

View file

@ -1,10 +1,39 @@
import json import json
#####################
### Configuration ###
#####################
CONFIG = json.loads(open("/config/config.json").read()) CONFIG = json.loads(open("/config/config.json").read())
# Colors Array
def colors(): def colors():
try: try:
return json.loads(open("/config/colors.json").read()) return json.loads(open("/config/colors.json").read())
except: except:
return None 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 import flask
from htmlpy import Link from htmlpy import Link
######################
### Site Functions ###
######################
# Check if request is from onion
def is_onion(req: flask.globals.request) -> bool: def is_onion(req: flask.globals.request) -> bool:
return req.host.endswith("onion") return req.host.endswith("onion")
# Check if request is from i2p
def is_i2p(req: flask.globals.request) -> bool: def is_i2p(req: flask.globals.request) -> bool:
return req.host.endswith("i2p") return req.host.endswith("i2p")
# Return dynamic link depending on request origin
def dynamic_link( def dynamic_link(
inner, normal: str, onion: str, i2p: str, req: flask.globals.request inner, normal: str, onion: str, i2p: str, req: flask.globals.request
) -> Link: ) -> Link:
@ -20,6 +27,7 @@ def dynamic_link(
return Link(normal, inner) return Link(normal, inner)
# Check if request is from common browsers
def is_browser(req: flask.globals.request) -> bool: def is_browser(req: flask.globals.request) -> bool:
ua = req.user_agent.string.lower() ua = req.user_agent.string.lower()
if "chrome" in ua or "safari" in ua or "firefox" in ua: if "chrome" in ua or "safari" in ua or "firefox" in ua:

View file

@ -1,25 +1,34 @@
import requests import requests
import os import os
from htmlpy import * 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 # Wrapper for Base HTML
def buildSite(content, title=None, disable_color=False, shadow=True): def buildSite(content, title=None, disable_color=False, shadow=True):
c_class = "bg-dark text-white justify-content-center text-center" c_class = "bg-dark text-white justify-content-center text-center"
c_style = "" c_style = ""
g_style = "a {text-decoration: none; font-weight: bold; color: white}"
if not disable_color: if not disable_color:
if colors() is not None: if colors() is not None:
c_class = "justify-content-center text-center" c_class = "justify-content-center text-center"
fg = colors()["special"]["foreground"] fg = fg_color()
bg = colors()["special"]["background"] bg = bg_color()
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}"]
c_style = f"background: {bg}; color: {fg};" 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"): if os.path.exists("/config/wall.avif"):
c_style += "background-image: url('assets/wall');background-size:cover;" 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( body=Body(
content, [Style(g_style), content],
global_attr=GlobalAttributes(css_class=c_class, style=c_style), 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", "https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js",
"/app/static/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 # Bootstrap CSS

View file

@ -4,8 +4,8 @@ import gnupg
from flask import request, Blueprint, Response, redirect from flask import request, Blueprint, Response, redirect
from htmlpy import * from htmlpy import *
from config import CONFIG, colors from config import CONFIG, colors, fg_color, bg_color
from html_fn import buildSite from html_fn import buildSite, Icon
from msg import encrypt, save_message from msg import encrypt, save_message
from notification import notify from notification import notify
from fn import is_browser from fn import is_browser
@ -189,7 +189,7 @@ def public_key():
def build_contact_block(): def build_contact_block():
return Div( return Div(
[ [
Heading(1, "Contact"), Heading(1, [Icon("person-lines-fill"), "Contact"]),
ThematicBreak(), ThematicBreak(),
[ [
Link("/public_key", "My PGP Key"), Link("/public_key", "My PGP Key"),
@ -211,7 +211,7 @@ def build_contact_block():
def build_donation_block(): def build_donation_block():
return Div( return Div(
[ [
Heading(1, "Donation"), Heading(1, [Icon("cash-coin", True), "Donation"]),
ThematicBreak(), ThematicBreak(),
Paragraph( Paragraph(
[ [

View file

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

View file

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