diff --git a/docs/config.json.md b/docs/config.json.md index 9023720..f6a188e 100644 --- a/docs/config.json.md +++ b/docs/config.json.md @@ -8,4 +8,7 @@ - `notify` : Notification Object - - `gotify`: Gotify Object - - - `token` : Gotify Token -- - - `host` : Gotify Host/Domain name \ No newline at end of file +- - - `host` : Gotify Host/Domain name +- `colors` +- - - `fg` : Color Number in colors.json +- - - `bg` : Color Number in colors.json \ No newline at end of file diff --git a/docs/configuration.md b/docs/configuration.md index 06a2d4d..edb7344 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -13,4 +13,10 @@ If you want to show a picture on the main page, place a file called `me.avif` in If you want to share your public key, put it inside `pub.key`. ## Mirrors -Specify mirror urls inside of `mirrors.txt` and it will be served at `/mirrors.txt` \ No newline at end of file +Specify mirror urls inside of `mirrors.txt` and it will be served at `/mirrors.txt` + +## Color Scheme +The site colors can be configured with pywal. Place pywal's colors.json in the config folder. + +## Background +To set a background picture place it at `config/wall.png` \ No newline at end of file diff --git a/src/assets.py b/src/assets.py index f3217c9..05e41c3 100644 --- a/src/assets.py +++ b/src/assets.py @@ -16,3 +16,8 @@ def filesend(path): @asset_pages.route("/me", methods=["GET"]) def me_picture(): return filesend("/config/me.avif") + + +@asset_pages.route("/wall") +def wall_bg(): + return filesend("/config/wall.png") diff --git a/src/config.py b/src/config.py index 1488ae5..92048fc 100644 --- a/src/config.py +++ b/src/config.py @@ -1,3 +1,10 @@ import json CONFIG = json.loads(open("/config/config.json").read()) + + +def colors(): + try: + return json.loads(open("/config/colors.json").read()) + except: + return None diff --git a/src/html_fn.py b/src/html_fn.py index ff7e761..eed19c2 100644 --- a/src/html_fn.py +++ b/src/html_fn.py @@ -1,9 +1,29 @@ import requests import os from htmlpy import * +from config import colors, CONFIG # Wrapper for Base HTML -def buildSite(content, title=None): +def buildSite(content, title=None, disable_color=False): + 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.png"): + c_style += "background-image: url('assets/wall');" + return Document( head=Head( [ @@ -17,9 +37,7 @@ def buildSite(content, title=None): ), body=Body( content, - global_attr=GlobalAttributes( - css_class="bg-dark text-white justify-content-center text-center" - ), + global_attr=GlobalAttributes(css_class=c_class, style=c_style), ), ) diff --git a/src/index.py b/src/index.py index 455fa45..5d8b879 100644 --- a/src/index.py +++ b/src/index.py @@ -4,7 +4,7 @@ import gnupg from flask import request, Blueprint, Response, redirect from htmlpy import * -from config import CONFIG +from config import CONFIG, colors from html_fn import buildSite from msg import encrypt, save_message from notification import notify @@ -12,6 +12,35 @@ from fn import is_browser main_pages = Blueprint("main", __name__) +# Color Scheme +@main_pages.route("/color") +def color(): + if colors() is None: + return "" + colors_p = [Heading(1, "Color 0")] + for i in range(0, 16): + c = colors()["colors"][f"color{i}"] + colors_p.append( + Heading( + 1, f"Color {i+1}", global_attr=GlobalAttributes(style=f"color: {c}") + ) + ) + site = buildSite([], "Colors") + + bg = colors()["special"]["background"] + fg = colors()["special"]["foreground"] + cur = colors()["special"]["cursor"] + site.body = Body( + [Div([colors_p], global_attr=GlobalAttributes(css_class="container"))], + global_attr=GlobalAttributes( + style=f"background: {bg}; color: {fg}", + css_class="justify-content-center text-center", + ), + ) + + return site.to_code() + + # Mirrors @main_pages.route("/mirrors.txt", methods=["GET"]) def mirrors(): @@ -19,14 +48,14 @@ def mirrors(): if exists("/config/mirrors.txt"): txt = open("/config/mirrors.txt").read() if is_browser(request): - site = buildSite(None, "Mirrors") - - site.body = Body( - content=Div( + site = buildSite( + Div( f"
{txt}", + global_attr=GlobalAttributes(style="margin: 25px;"), ), - global_attr=GlobalAttributes(style="background: black; color: white"), + "Mirrors", ) + return site.to_code() return txt @@ -144,6 +173,7 @@ def public_key(): ), ], "Public Key", + disable_color=True, ).to_code() # Return raw key