From 743a8d6916f4d3170479cfad5459eb8d5f303c4d Mon Sep 17 00:00:00 2001
From: Nathan Woodburn
Date: Sat, 18 Nov 2023 17:56:08 +1100
Subject: [PATCH] feat: Add blank template and footer part
---
main.py | 2 +-
sites/parts/footer.html | 6 ++++
sites/website.py | 58 +++++++++++++++++++++--------------
templates/city.html | 9 +-----
templates/city_blank.html | 58 +++++++++++++++++++++++++++++++++++
templates/city_no_card.html | 10 ++----
templates/city_no_card_2.html | 10 ++----
templates/city_old.html | 9 +-----
templates/city_template.html | 10 ++----
9 files changed, 108 insertions(+), 64 deletions(-)
create mode 100644 sites/parts/footer.html
create mode 100644 templates/city_blank.html
diff --git a/main.py b/main.py
index 0023e94..9a69b95 100644
--- a/main.py
+++ b/main.py
@@ -34,7 +34,7 @@ if IMAGE_LOCATION == None:
random_sites = ""
# Templates available for user
-templates = ['Standard', 'Original', 'No card around data', 'No card around data (2)']
+templates = ['Standard', 'Original', 'No card around data', 'No card around data (2)','Blank']
#Assets routes
@app.route('/assets/')
diff --git a/sites/parts/footer.html b/sites/parts/footer.html
new file mode 100644
index 0000000..8ec9b95
--- /dev/null
+++ b/sites/parts/footer.html
@@ -0,0 +1,6 @@
+
\ No newline at end of file
diff --git a/sites/website.py b/sites/website.py
index 31378ed..6b9986b 100644
--- a/sites/website.py
+++ b/sites/website.py
@@ -1,4 +1,4 @@
-from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory
+from flask import Flask, redirect, render_template_string, request
from bs4 import BeautifulSoup
import os
import dotenv
@@ -7,6 +7,11 @@ main_domain = "cities.hnshosting.au"
if os.getenv('MAIN_DOMAIN') != None:
main_domain = os.getenv('MAIN_DOMAIN')
+FOOTER=""
+if os.path.exists("parts/footer.html"):
+ with open("parts/footer.html") as f:
+ FOOTER = f.read()
+
def render(data,db_object):
if data == False:
return redirect("https://" + main_domain + '/claim?domain=' + request.host.split('.')[0])
@@ -19,8 +24,9 @@ def render(data,db_object):
try:
soup = BeautifulSoup(data, 'html.parser')
- for script in soup.find_all('script'):
- script.extract()
+
+ # for script in soup.find_all('script'):
+ # script.extract()
# Inject SSL
soup.append(BeautifulSoup(ssl, 'html.parser'))
@@ -82,23 +88,22 @@ def render(data,db_object):
if db_object['template'] != "":
template = db_object['template']
+ footer = render_template_string(FOOTER,main_domain=main_domain,fg_colour=fg_colour,hns_icon=hns_icon)
if hide_addresses:
- return render_template_string(get_template_without_address(template),bg_colour=bg_colour,text_colour=text_colour,
+ return render_template_string(get_template(template,True),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)
+ hns=hns,btc=btc,eth=eth, data=html,footer=footer)
else:
- return render_template(get_template_file(template),bg_colour=bg_colour,text_colour=text_colour,
+ return render_template_string(get_template(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)
+ hns=hns,btc=btc,eth=eth, data=html,footer=footer)
except Exception as e:
return "Nothing here yet
" + ""
-
-
-def get_template_without_address(template):
+def get_template(template,hide_addresses=False):
file = "templates/" +get_template_file(template)
with open(file) as f:
data = f.read()
@@ -106,13 +111,14 @@ def get_template_without_address(template):
# Read template
soup = BeautifulSoup(data, 'html.parser')
# Remove addresses div
- try:
- addresses = soup.find(id="addresses")
- addresses.decompose()
- finally:
- # Return template without addresses
- return str(soup)
-
+ if hide_addresses:
+ try:
+ addresses = soup.find(id="addresses")
+ addresses.decompose()
+ except:
+ pass
+
+ return str(soup)
def calculate_contrast_ratio(color1, color2):
def calculate_luminance(color):
@@ -156,11 +162,17 @@ def rgb_to_hex(rgb_color):
def get_template_file(template):
- if template == "Original":
- return "city_old.html"
- elif template == "No card around data":
- return "city_no_card.html"
- elif template == "No card around data (2)":
- return "city_no_card_2.html"
+ template = template.lower()
+ templates = {
+ "standard": "city.html",
+ "original": "city_old.html",
+ "no card around data": "city_no_card.html",
+ "no card around data (2)": "city_no_card_2.html",
+ "blank": "city_blank.html"
+ }
+
+ if template in templates:
+ return templates[template]
+
return "city.html"
\ No newline at end of file
diff --git a/templates/city.html b/templates/city.html
index 6db7d53..c04f1a9 100644
--- a/templates/city.html
+++ b/templates/city.html
@@ -56,14 +56,7 @@
{{eth|safe}}
-
-
-
+ {{footer | safe}}
+
+
+ {{data|safe}}
+
+ {{footer|safe}}
+
+
+
diff --git a/templates/city_blank.html b/templates/city_blank.html
new file mode 100644
index 0000000..f66e21c
--- /dev/null
+++ b/templates/city_blank.html
@@ -0,0 +1,58 @@
+
+
+
+