import requests
import os
from htmlpy import *
from config import colors, CONFIG
# 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 = ""
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}"]
c_style = f"background: {bg}; color: {fg};"
if os.path.exists("/config/wall.avif"):
c_style += "background-image: url('assets/wall');background-size:cover;"
if shadow:
c_style += "text-shadow: 1px 1px 3px black;"
return Document(
head=Head(
[
Title(title),
Meta(
name="viewport",
content="user-scalable=no, width=device-width, initial-scale=1.0",
),
BOOTSTRAP,
]
),
body=Body(
content,
global_attr=GlobalAttributes(css_class=c_class, style=c_style),
),
)
def download_file(url, file):
os.makedirs("/app/static/", exist_ok=True)
r = requests.get(url, allow_redirects=True)
open(file, "wb").write(r.content)
# Downloads all bootstrap files to flasks static directory
def cache_bootstrap():
download_file(
"https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css",
"/app/static/bootstrap.min.css",
)
download_file(
"https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css",
"/app/static/bootstrap-icons.css",
)
download_file(
"https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js",
"/app/static/bootstrap.bundle.min.js",
)
# Bootstrap CSS
BOOTSTRAP = [
Reference(
"/static/bootstrap.min.css",
"stylesheet",
),
Reference(
"/static/bootstrap-icons.css",
"stylesheet",
),
Script(src="/static/bootstrap.bundle.min.js"),
]