From e28f11e840de6276ed6fe2598ffc4b5699717fed Mon Sep 17 00:00:00 2001 From: TriMill Date: Sat, 31 Dec 2022 19:00:52 -0500 Subject: [PATCH] no more js, font change --- flaskr/__init__.py | 25 ++++++++++++++++++------- flaskr/static/style.css | 20 ++++++++++---------- flaskr/templates/_base.html | 23 +++++------------------ 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/flaskr/__init__.py b/flaskr/__init__.py index e810c25..1ca60b1 100644 --- a/flaskr/__init__.py +++ b/flaskr/__init__.py @@ -101,17 +101,23 @@ def create_app(): theme = request.cookies.get("theme") or "dark" return render_template("404.html", data=data, theme=theme), 404 - def load_page(url): + def _load_page(url): if url.endswith(".html"): path = os.path.join(app.root_path, app.template_folder, url) if os.path.exists(path): - theme = request.cookies.get("theme") or "dark" + theme = request.args.get("theme") or request.cookies.get("theme") or "dark" return render_template(url, data=data, theme=theme) else: return abort(404) else: return send_from_directory("templates", url) + def load_page(url): + resp = make_response(_load_page(url)) + if request.args.get("theme"): + resp.set_cookie("theme", request.args["theme"]) + return resp + @app.route("/") @app.route("/index.html") def home(): @@ -129,9 +135,11 @@ def create_app(): @app.route("/blog/") def blog_list(): - theme = request.cookies.get("theme") or "dark" - return render_template("blog.html", data=data, theme=theme) - + theme = request.args.get("theme") or request.cookies.get("theme") or "dark" + resp = make_response(render_template("blog.html", data=data, theme=theme)) + if request.args.get("theme"): + resp.set_cookie("theme", request.args["theme"]) + return resp @app.route("/blog////") @app.route("/blog////") @@ -144,8 +152,11 @@ def create_app(): contents = f.read() content = markdown2.markdown(contents, extras=markdown_extras) meta = content.metadata - theme = request.cookies.get("theme") or "dark" - return render_template("_blog.html", data=data, theme=theme, content=content, date=date, meta=meta) + theme = request.args.get("theme") or request.cookies.get("theme") or "dark" + resp = make_response(render_template("_blog.html", data=data, theme=theme, content=content, date=date, meta=meta)) + if request.args.get("theme"): + resp.set_cookie("theme", request.args["theme"]) + return resp else: return abort(404) diff --git a/flaskr/static/style.css b/flaskr/static/style.css index 0bdcb9e..d4d8839 100644 --- a/flaskr/static/style.css +++ b/flaskr/static/style.css @@ -1,7 +1,7 @@ -@import url('https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@500&family=Source+Sans+Pro:wght@400&family=Fira+Mono&display=swap'); +@import url('https://fonts.googleapis.com/css2?family=Fira+Mono:wght@400;700&family=Lato:ital,wght@0,400;0,700;1,400;1,700&family=Roboto+Slab:wght@500&display=swap'); @media (prefers-color-scheme: dark) { - :root[theme="system"] { + :root.theme-system { --bg: #242328; --bg-intense: #141316; --bg-faded: #373338; @@ -19,7 +19,7 @@ } @media (prefers-color-scheme: light) { - :root[theme="system"] { + :root.theme-system { --bg: #f6f5f2; --bg-intense: #ffffff; --bg-faded: #cbc4c7; @@ -36,7 +36,7 @@ } } -:root[theme="dark"] { +:root.theme-dark { --bg: #242328; --bg-intense: #141316; --bg-faded: #373338; @@ -49,7 +49,7 @@ --error: #ee6d7d; } -:root[theme="light"] { +:root.theme-light { --bg: #f6f5f2; --bg-intense: #ffffff; --bg-faded: #cbc4c7; @@ -62,7 +62,7 @@ --error: #a50518; } -:root[theme="contrast"] { +:root.theme-contrast { --bg: white; --bg-intense: white; --bg-faded: #d0d0d0; @@ -75,7 +75,7 @@ --error: #880000; } -:root[theme="contrast-dark"] { +:root.theme-contrast-dark { --bg: black; --bg-intense: black; --bg-faded: #333333; @@ -88,7 +88,7 @@ --error: #ff8888; } -:root[theme="special"] { +:root.theme-special { --bg: #ffff00; --bg-intense: #ffffff; --bg-faded: #00ff00; @@ -104,7 +104,7 @@ :root { color: var(--fg); - font-family: "Source Sans Pro", sans-serif; + font-family: "Lato", sans-serif; font-size: 20px; font-weight: 400; line-height: 1.5; @@ -234,7 +234,7 @@ button, input, select, textarea { background-color: var(--bg-faded); border: 2px solid var(--fg-faded); border-radius: 3px; - font-family: "Source Sans Pro", sans-serif; + font-family: "Lato", sans-serif; font-size: 16px; } diff --git a/flaskr/templates/_base.html b/flaskr/templates/_base.html index 9397e13..a085410 100644 --- a/flaskr/templates/_base.html +++ b/flaskr/templates/_base.html @@ -1,5 +1,5 @@ - + @@ -31,22 +31,6 @@ - {% block head %} {% endblock %} @@ -55,7 +39,9 @@ Home · Projects · Blog™ · - + + + {% if theme == "dark" %} Dark theme @@ -76,6 +62,7 @@ System default theme {% endif %} +