color scheme

This commit is contained in:
JMARyA 2022-09-13 07:40:17 +02:00
parent c3d63a25fc
commit 6d158832e9
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 81 additions and 12 deletions

View file

@ -9,3 +9,6 @@
- - `gotify`: Gotify Object - - `gotify`: Gotify Object
- - - `token` : Gotify Token - - - `token` : Gotify Token
- - - `host` : Gotify Host/Domain name - - - `host` : Gotify Host/Domain name
- `colors`
- - - `fg` : Color Number in colors.json
- - - `bg` : Color Number in colors.json

View file

@ -14,3 +14,9 @@ If you want to share your public key, put it inside `pub.key`.
## Mirrors ## Mirrors
Specify mirror urls inside of `mirrors.txt` and it will be served at `/mirrors.txt` 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`

View file

@ -16,3 +16,8 @@ def filesend(path):
@asset_pages.route("/me", methods=["GET"]) @asset_pages.route("/me", methods=["GET"])
def me_picture(): def me_picture():
return filesend("/config/me.avif") return filesend("/config/me.avif")
@asset_pages.route("/wall")
def wall_bg():
return filesend("/config/wall.png")

View file

@ -1,3 +1,10 @@
import json import json
CONFIG = json.loads(open("/config/config.json").read()) CONFIG = json.loads(open("/config/config.json").read())
def colors():
try:
return json.loads(open("/config/colors.json").read())
except:
return None

View file

@ -1,9 +1,29 @@
import requests import requests
import os import os
from htmlpy import * from htmlpy import *
from config import colors, CONFIG
# Wrapper for Base HTML # 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( return Document(
head=Head( head=Head(
[ [
@ -17,9 +37,7 @@ def buildSite(content, title=None):
), ),
body=Body( body=Body(
content, content,
global_attr=GlobalAttributes( global_attr=GlobalAttributes(css_class=c_class, style=c_style),
css_class="bg-dark text-white justify-content-center text-center"
),
), ),
) )

View file

@ -4,7 +4,7 @@ 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 from config import CONFIG, colors
from html_fn import buildSite from html_fn import buildSite
from msg import encrypt, save_message from msg import encrypt, save_message
from notification import notify from notification import notify
@ -12,6 +12,35 @@ from fn import is_browser
main_pages = Blueprint("main", __name__) 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 # Mirrors
@main_pages.route("/mirrors.txt", methods=["GET"]) @main_pages.route("/mirrors.txt", methods=["GET"])
def mirrors(): def mirrors():
@ -19,14 +48,14 @@ def mirrors():
if exists("/config/mirrors.txt"): if exists("/config/mirrors.txt"):
txt = open("/config/mirrors.txt").read() txt = open("/config/mirrors.txt").read()
if is_browser(request): if is_browser(request):
site = buildSite(None, "Mirrors") site = buildSite(
Div(
site.body = Body(
content=Div(
f"<pre>{txt}</pre>", f"<pre>{txt}</pre>",
global_attr=GlobalAttributes(style="margin: 25px;"),
), ),
global_attr=GlobalAttributes(style="background: black; color: white"), "Mirrors",
) )
return site.to_code() return site.to_code()
return txt return txt
@ -144,6 +173,7 @@ def public_key():
), ),
], ],
"Public Key", "Public Key",
disable_color=True,
).to_code() ).to_code()
# Return raw key # Return raw key