some stuff and favicon

This commit is contained in:
trinkey 2024-12-20 23:44:40 -05:00
parent b2c3cc4c3d
commit b25eb372d2
8 changed files with 84 additions and 20 deletions

View file

@ -1,3 +1,4 @@
django django
django-cors-headers django-cors-headers
requests requests
cariosvg

View file

@ -24,6 +24,11 @@ body {
font-size: 18px; font-size: 18px;
} }
::selection {
background-color: var(--accent);
color: var(--base);
}
code, pre { code, pre {
font-family: "Ubuntu Mono" font-family: "Ubuntu Mono"
} }
@ -71,15 +76,20 @@ button {
color: var(--text); color: var(--text);
font-family: "DejaVu Sans"; font-family: "DejaVu Sans";
outline: 1px solid var(--surface0); outline: 1px solid var(--surface0);
padding: 4px 8px; padding: 4px 6px;
min-width: 75px; min-width: 75px;
border: none; border: none;
margin: 2px 0; margin: 2px 0;
border-radius: 8px; border-radius: 99999px;
cursor: pointer; cursor: pointer;
transition: outline-color 0.25s, background-color 0.25s; transition: outline-color 0.25s, background-color 0.25s;
} }
ul,
ol {
padding-left: 15px;
}
input[type="submit"]:focus, input[type="submit"]:focus,
button:focus { button:focus {
outline-color: var(--accent); outline-color: var(--accent);

View file

@ -1,16 +1,6 @@
let _themeMM = matchMedia("(prefers-color-scheme: light)"); let _themeMM = matchMedia("(prefers-color-scheme: light)");
let light, useAutoTheme; let light, useAutoTheme;
// {% if theme == "auto" %} light = _themeMM.matches;
light = _themeMM.matches;
useAutoTheme = true;
// {% else %}
// {% if theme == "light" %}
light = true;
// {% else %}
light = false;
// {% endif %}
useAutoTheme = false;
// {% endif %}
function setTheme() { function setTheme() {
if (light) { if (light) {
@ -21,10 +11,8 @@ function setTheme() {
} }
_themeMM.addEventListener("change", function() { _themeMM.addEventListener("change", function() {
if (useAutoTheme) {
light = _themeMM.matches; light = _themeMM.matches;
setTheme(); setTheme();
}
}); });
setTheme(); setTheme();

View file

@ -1,8 +1,9 @@
from django.urls import include, path from django.urls import include, path
from .views import initialize from .views import generate_favicon, initialize
urlpatterns = [ urlpatterns = [
path("api/initialize/", initialize), path("api/initialize/", initialize),
path("favicon/<str:theme>/<str:accent>/", generate_favicon),
path("static/", include("tcommon.views.static")) path("static/", include("tcommon.views.static"))
] ]

View file

@ -1 +1,2 @@
from .api import initialize # noqa: F401 from .api import initialize # noqa: F401
from .favicon import generate_favicon # noqa: F401

View file

@ -21,6 +21,7 @@ def initialize(request: WSGIRequest) -> HttpResponse:
resp = { resp = {
"debug": DEBUG, "debug": DEBUG,
"version": list(VERSION), "version": list(VERSION),
"version_str": ".".join([str(i) for i in VERSION]),
"success": True, "success": True,
"services": { "services": {
"common": { "common": {

62
tcommon/views/favicon.py Normal file
View file

@ -0,0 +1,62 @@
from cairosvg import svg2png
from django.http import HttpResponse, HttpResponseServerError
from django.views.decorators.cache import cache_page
favicon = """<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64">
<rect width="64" height="64" x=".253" y=".167" fill="{{ BASE }}" rx="16"/>
<path fill="{{ ACCENT }}" d="M34.906 7v11.057H47.75v8.901H34.906v16.516q0 2.712 1.08 3.669 1.078.956 4.28.956h6.405V57H35.985q-7.379 0-10.459-3.077t-3.08-10.449V26.958H16.25v-8.901h6.196V7Z"/>
</svg>"""
colors = {
"base": {
"light": "#eff1f5",
"dark": "#1e1e2e"
},
"accent": {
"light": {
"rosewater": "#dc8a78",
"flamingo": "#dd7878",
"pink": "#ea76cb",
"mauve": "#8839ef",
"red": "#d20f39",
"maroon": "#e64553",
"peach": "#fe640b",
"yellow": "#df8e1d",
"green": "#40a02b",
"teal": "#179299",
"sky": "#04a5e5",
"sapphire": "#209fb5",
"blue": "#1e66f5",
"lavender": "#7287fd"
},
"dark": {
"rosewater": "#f5e0dc",
"flamingo": "#f2cdcd",
"pink": "#f5c2e7",
"mauve": "#cba6f7",
"red": "#f38ba8",
"maroon": "#eba0ac",
"peach": "#fab387",
"yellow": "#f9e2af",
"green": "#a6e3a1",
"teal": "#94e2d5",
"sky": "#89dceb",
"sapphire": "#74c7ec",
"blue": "#89b4fa",
"lavender": "#b4befe"
}
}
}
@cache_page(60 * 60 * 2)
def generate_favicon(request, theme, accent) -> HttpResponse | HttpResponseServerError:
png_data: bytes | None = svg2png(
favicon.replace("{{ BASE }}", colors["base"][theme]).replace("{{ ACCENT }}", colors["accent"][theme][accent]),
output_width=64,
output_height=64
)
if not isinstance(png_data, bytes):
return HttpResponseServerError("500 Internal Server Error")
return HttpResponse(png_data, content_type="image/png")

View file

@ -1,6 +1,6 @@
from django.http import HttpResponse from django.http import HttpResponse
from django.urls import path from django.urls import path
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_control
from tcommon.settings import STATIC_DIR from tcommon.settings import STATIC_DIR
@ -21,7 +21,7 @@ file_associations = {
"ttf": "font/ttf" "ttf": "font/ttf"
} }
urlpatterns = [path(i, cache_page(60 * 60 * 24 * 30)(get_static_serve(i, file_associations[i.split(".")[-1]]))) for i in [ urlpatterns = [path(i, cache_control(**{"max-age": 60 * 60 * 24 * 30})(get_static_serve(i, file_associations[i.split(".")[-1]]))) for i in [
"css/base.css", "css/base.css",
"js/theme.js", "js/theme.js",
"font/DejaVuSans-Bold.ttf", "font/DejaVuSans-Bold.ttf",