From b6af12e7518780e7501371ae8faf053921165cb7 Mon Sep 17 00:00:00 2001 From: Krateng Date: Fri, 8 Mar 2019 13:36:26 +0100 Subject: [PATCH] Added global footer and head elements --- server.py | 37 +++++++------ website/artist.html | 1 - website/common/footer.html | 13 +++++ website/common/header.html | 86 ++++++++++++++++++++++++++++++ website/issues.html | 1 - website/pulse.html | 1 - website/scrobbles.html | 1 - website/setup.html | 1 - website/start.html | 104 +------------------------------------ website/topartists.html | 1 - website/toptracks.html | 1 - website/track.html | 1 - website/wait.html | 1 - 13 files changed, 123 insertions(+), 126 deletions(-) create mode 100644 website/common/footer.html create mode 100644 website/common/header.html diff --git a/server.py b/server.py index bab37d1..05a67a2 100755 --- a/server.py +++ b/server.py @@ -131,6 +131,16 @@ def static_html(name): linkheaders = ["; rel=preload; as=style"] keys = removeIdentical(FormsDict.decode(request.query)) + with open("website/" + name + ".html") as htmlfile: + html = htmlfile.read() + + # apply global substitutions + with open("website/common/footer.html") as footerfile: + footerhtml = footerfile.read() + with open("website/common/header.html") as headerfile: + headerhtml = headerfile.read() + html = html.replace("",footerhtml + "").replace("",headerhtml + "") + # If a python file exists, it provides the replacement dict for the html file if os.path.exists("website/" + name + ".py"): #txt_keys = SourceFileLoader(name,"website/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT) @@ -141,23 +151,20 @@ def static_html(name): linkheaders.append("<" + resource["file"] + ">; rel=preload; as=" + resource["type"]) # apply key substitutions - with open("website/" + name + ".html") as htmlfile: - html = htmlfile.read() - for k in txt_keys: - if isinstance(txt_keys[k],list): - # if list, we replace each occurence with the next item - for element in txt_keys[k]: - html = html.replace(k,element,1) - else: - html = html.replace(k,txt_keys[k]) - - response.set_header("Link",",".join(linkheaders)) - return html + for k in txt_keys: + if isinstance(txt_keys[k],list): + # if list, we replace each occurence with the next item + for element in txt_keys[k]: + html = html.replace(k,element,1) + else: + html = html.replace(k,txt_keys[k]) - - # Otherwise, we just serve the html file + + response.set_header("Link",",".join(linkheaders)) - return static_file("website/" + name + ".html",root="") + + return html + #return static_file("website/" + name + ".html",root="") #set graceful shutdown signal.signal(signal.SIGINT, graceful_exit) diff --git a/website/artist.html b/website/artist.html index f14fa13..c563d2e 100644 --- a/website/artist.html +++ b/website/artist.html @@ -4,7 +4,6 @@ Maloja - KEY_ARTISTNAME - diff --git a/website/common/footer.html b/website/common/footer.html new file mode 100644 index 0000000..88d8980 --- /dev/null +++ b/website/common/footer.html @@ -0,0 +1,13 @@ + diff --git a/website/common/header.html b/website/common/header.html new file mode 100644 index 0000000..cee4d3c --- /dev/null +++ b/website/common/header.html @@ -0,0 +1,86 @@ + + + + + + diff --git a/website/issues.html b/website/issues.html index 9853bdc..149d977 100644 --- a/website/issues.html +++ b/website/issues.html @@ -4,7 +4,6 @@ Maloja - Issues - diff --git a/website/pulse.html b/website/pulse.html index 2ea5f54..57ff21b 100644 --- a/website/pulse.html +++ b/website/pulse.html @@ -4,7 +4,6 @@ Maloja - KEY_PULSEDETAILS Pulse - diff --git a/website/scrobbles.html b/website/scrobbles.html index bccdda0..5b47c11 100644 --- a/website/scrobbles.html +++ b/website/scrobbles.html @@ -4,7 +4,6 @@ Maloja - Scrobbles - diff --git a/website/setup.html b/website/setup.html index 490ac6b..58ac1af 100644 --- a/website/setup.html +++ b/website/setup.html @@ -4,7 +4,6 @@ Maloja - Setup - @@ -215,28 +135,8 @@ - - - - - - + - diff --git a/website/topartists.html b/website/topartists.html index ed5d21e..32d0704 100644 --- a/website/topartists.html +++ b/website/topartists.html @@ -4,7 +4,6 @@ Maloja - Top Artists KEY_RANGE - diff --git a/website/toptracks.html b/website/toptracks.html index 4df6b34..c12899d 100644 --- a/website/toptracks.html +++ b/website/toptracks.html @@ -4,7 +4,6 @@ Maloja - Top Tracks in KEY_RANGE - diff --git a/website/track.html b/website/track.html index 9891c7f..7880905 100644 --- a/website/track.html +++ b/website/track.html @@ -4,7 +4,6 @@ Maloja - KEY_TRACKTITLE - diff --git a/website/wait.html b/website/wait.html index dc6e8f5..d961a55 100644 --- a/website/wait.html +++ b/website/wait.html @@ -4,7 +4,6 @@ Maloja - Please wait -