feat: Add function to allow for template testing
This commit is contained in:
parent
8f1b141828
commit
2c419d73a2
16
README.md
16
README.md
@ -7,6 +7,22 @@ Every domain comes enabled with HTTPS via DANE. We have support HIP02 aliases, s
|
||||
|
||||
|
||||
|
||||
### Template testing
|
||||
|
||||
Replace `new` with your template name
|
||||
|
||||
```sh
|
||||
cd <Git-REPONAME>
|
||||
# Copy template
|
||||
cp templates/city_template.html templates/city_new.html
|
||||
# Edit template
|
||||
# Test site with template
|
||||
python3 -m pip install -r requirements.txt
|
||||
python3 template.py city_new
|
||||
```
|
||||
|
||||
Visit http://127.0.0.1:5000/ to view the template
|
||||
|
||||
|
||||
### Deployment
|
||||
```
|
||||
|
@ -16,7 +16,7 @@ def render(data,db_object):
|
||||
if data == False:
|
||||
return redirect("https://" + main_domain + '/claim?domain=' + request.host.split('.')[0])
|
||||
elif data == "":
|
||||
return redirect("https://" + main_domain + '/empty_site')
|
||||
return redirect("https://" + main_domain + '/empty_site?nodata')
|
||||
|
||||
# Render as HTML
|
||||
html = ""
|
||||
@ -31,7 +31,7 @@ def render(data,db_object):
|
||||
|
||||
html = str(soup)
|
||||
except Exception as e:
|
||||
return redirect("https://" + main_domain + '/empty_site')
|
||||
return redirect("https://" + main_domain + '/empty_site?error='+str(e))
|
||||
|
||||
try:
|
||||
avatar = db_object['avatar']
|
||||
@ -104,7 +104,7 @@ def render(data,db_object):
|
||||
hns=hns,btc=btc,eth=eth, data=html,footer=footer)
|
||||
|
||||
except Exception as e:
|
||||
return redirect("https://" + main_domain + '/empty_site')
|
||||
return redirect("https://" + main_domain + '/empty_site?error='+str(e))
|
||||
|
||||
def get_template(template,hide_addresses=False):
|
||||
file = "templates/" +get_template_file(template)
|
||||
@ -165,6 +165,10 @@ def rgb_to_hex(rgb_color):
|
||||
|
||||
|
||||
def get_template_file(template):
|
||||
if template.endswith(".html"):
|
||||
return template
|
||||
|
||||
|
||||
template = template.lower()
|
||||
templates = {
|
||||
"standard": "city.html",
|
||||
|
60
template.py
Normal file
60
template.py
Normal file
@ -0,0 +1,60 @@
|
||||
from flask import Flask, send_from_directory
|
||||
import sys
|
||||
import sites.website as website
|
||||
import json
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
template = "city"
|
||||
data = "<h1>Test site</h1><p>This is a test site</p>"
|
||||
db_object = {
|
||||
'avatar': "https://woodburn.au/favicon.png",
|
||||
'hnschat':"nathan.woodburn",
|
||||
'location': "Australia",
|
||||
'email': "test@email",
|
||||
'HNS': "hs1...",
|
||||
'BTC': "bc1...",
|
||||
'ETH' : "0x...",
|
||||
'bg_colour': "#000000",
|
||||
'fg_colour': "#ffffff",
|
||||
'text_colour': "#152D45",
|
||||
}
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
if os.path.exists("templates/"+template+".html"):
|
||||
with open("templates/"+template+".html") as f:
|
||||
filedata = f.read()
|
||||
filedata = filedata.replace('#f1ffff', '{{fg_colour}}')
|
||||
filedata = filedata.replace('#1fffff', '{{text_colour}}')
|
||||
filedata = filedata.replace('#000000', '{{bg_colour}}')
|
||||
# Save
|
||||
with open('templates/' + template+".tmp.html", 'w') as f:
|
||||
f.write(filedata)
|
||||
else:
|
||||
return "Template not found"
|
||||
|
||||
db_object['template'] = template + ".tmp.html"
|
||||
render = website.render(data,db_object)
|
||||
|
||||
# Delete tmp
|
||||
os.remove('templates/' + template+".tmp.html")
|
||||
return render
|
||||
|
||||
@app.route('/assets/<path:path>')
|
||||
def send_assets(path):
|
||||
return send_from_directory('templates/assets', path)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Get second arg
|
||||
if len(sys.argv) > 1:
|
||||
template = sys.argv[1]
|
||||
else:
|
||||
print("Usage: python3 template.py <template>")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
Loading…
Reference in New Issue
Block a user