feat: Add option for selecting template
This commit is contained in:
@@ -54,17 +54,20 @@ def catch_all(path):
|
||||
def not_found(e):
|
||||
return redirect('/')
|
||||
|
||||
def clean_template():
|
||||
def clean_templates():
|
||||
# Clean template
|
||||
with open('templates/city.html') as f:
|
||||
data = f.read()
|
||||
|
||||
data = data.replace('#f1ffff', '{{fg_colour}}')
|
||||
data = data.replace('#1fffff', '{{text_colour}}')
|
||||
data = data.replace('#000000', '{{bg_colour}}')
|
||||
# Save
|
||||
with open('templates/city.html', 'w') as f:
|
||||
f.write(data)
|
||||
for file in os.listdir('templates'):
|
||||
if file.endswith('.html'):
|
||||
with open('templates/' + file) as f:
|
||||
data = f.read()
|
||||
|
||||
data = data.replace('#f1ffff', '{{fg_colour}}')
|
||||
data = data.replace('#1fffff', '{{text_colour}}')
|
||||
data = data.replace('#000000', '{{bg_colour}}')
|
||||
# Save
|
||||
with open('templates/' + file, 'w') as f:
|
||||
f.write(data)
|
||||
print("Cleaned " + file, flush=True)
|
||||
print("Cleaned template", flush=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -25,7 +25,7 @@ class GunicornApp(BaseApplication):
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Cleaning template...", flush=True)
|
||||
slds.clean_template()
|
||||
slds.clean_templates()
|
||||
workers = os.getenv('WORKERS')
|
||||
threads = os.getenv('THREADS')
|
||||
if workers is None:
|
||||
|
||||
@@ -66,9 +66,17 @@ def render(data,db_object):
|
||||
if email != "":
|
||||
email = "<a href='mailto:"+email+"'><img src='"+email_icon+"' width='30px' height='20px' style='margin-right: 5px;margin-left:-10px;'>" + email + "</a>"
|
||||
|
||||
|
||||
|
||||
if avatar != "":
|
||||
avatar = "<img src='"+avatar+"' width='200vw' height='200vw' style='border-radius: 50%;margin-right: 5px;'>"
|
||||
else:
|
||||
avatar = "<h1>" + request.host.split(':')[0] + "/</h1>"
|
||||
|
||||
if 'template' in db_object:
|
||||
if db_object['template'] != "":
|
||||
return render_template(get_template(db_object['template']),bg_colour=bg_colour,text_colour=text_colour,
|
||||
fg_colour=fg_colour, avatar=avatar,main_domain=main_domain,
|
||||
hnschat=hnschat,email=email,location=location, hns_icon=hns_icon,
|
||||
hns=hns,btc=btc,eth=eth, data=html)
|
||||
|
||||
except Exception as e:
|
||||
return "<h1>Invalid data</h1><br><h2>Please contact support</h2><br><p>This can often be fixed by saving your site again in the editor</p><br>" + "<script>console.log('" + str(e).replace('\'','') + "');</script>"
|
||||
@@ -120,3 +128,9 @@ def generate_foreground_color(background_color):
|
||||
|
||||
def rgb_to_hex(rgb_color):
|
||||
return "#{:02x}{:02x}{:02x}".format(*rgb_color)
|
||||
|
||||
def get_template(template):
|
||||
if template == "Original":
|
||||
return "city-old.html"
|
||||
|
||||
return "city.html"
|
||||
Reference in New Issue
Block a user