added theme support
This commit is contained in:
@ -27,6 +27,14 @@ def app(environ, start_response):
|
||||
"""The WSGI application that connects all together."""
|
||||
req = Request(environ)
|
||||
path = req.path[1:].lower()
|
||||
# do theme handling
|
||||
theme = 'light'
|
||||
if 'style' in req.cookies:
|
||||
theme = req.cookies['style']
|
||||
if 'theme' in req.args.keys():
|
||||
theme = req.args['theme']
|
||||
if not theme in ['light', 'dark']:
|
||||
theme = 'light'
|
||||
if path == '':
|
||||
path = 'index'
|
||||
mime_type='text/html'
|
||||
@ -44,7 +52,12 @@ def app(environ, start_response):
|
||||
tmpl = env.get_template(path + '.html')
|
||||
except TemplateNotFound:
|
||||
tmpl = env.get_template('not_found.html')
|
||||
resp = Response(tmpl.render(static=False), mimetype=mime_type)
|
||||
resp = Response(tmpl.render(static=False, theme=theme), mimetype=mime_type)
|
||||
# more theme handling
|
||||
if theme == 'light' and 'style' in req.cookies:
|
||||
resp.delete_cookie('style')
|
||||
elif theme != 'light':
|
||||
resp.set_cookie('style', theme)
|
||||
resp.add_etag()
|
||||
resp.make_conditional(req)
|
||||
return resp(environ, start_response)
|
||||
|
@ -5,8 +5,11 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
|
||||
<head>
|
||||
<title>{% filter capture('title') %}{% block title %}{% endblock %}{% endfilter %} - I2P</title>
|
||||
{% if theme == 'light' %}
|
||||
<link rel="stylesheet" href="_static/styles/default.css" type="text/css" title="Light">
|
||||
<link rel="alternate stylesheet" href="_static/styles/dark.css" type="text/css" title="Dark">
|
||||
{% else %}
|
||||
<link rel="stylesheet" href="_static/styles/dark.css" type="text/css" title="Dark">
|
||||
{% endif %}
|
||||
<link rel="shortcut icon" href="_static/favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
|
@ -6,8 +6,11 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
|
||||
<head>
|
||||
<title>{% filter capture('title') %}{% block title %}{% endblock %}{% endfilter %} - I2P</title>
|
||||
<link rel="stylesheet" href="_static/styles/default.css" type="text/css" title="light">
|
||||
<link rel="alternate stylesheet" href="_static/styles/dark.css" type="text/css" title="dark">
|
||||
{% if theme == 'light' %}
|
||||
<link rel="stylesheet" href="_static/styles/default.css" type="text/css" title="Light">
|
||||
{% else %}
|
||||
<link rel="stylesheet" href="_static/styles/dark.css" type="text/css" title="Dark">
|
||||
{% endif %}
|
||||
<link rel="shortcut icon" href="_static/favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
|
Reference in New Issue
Block a user