Add build date generation. Add render caching to make it less heavy on the filesystem, should speed site up somehow...
This commit is contained in:
parent
a2659f3768
commit
71949c087b
|
@ -15,6 +15,8 @@ COPY --from=builder /install /usr/local
|
|||
|
||||
COPY . /app
|
||||
|
||||
RUN date +%d-%m-%Y > /app/date
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
EXPOSE 8000
|
||||
|
|
57
app.py
57
app.py
|
@ -11,40 +11,35 @@ app = Flask(__name__, static_url_path="", static_folder="static")
|
|||
|
||||
file_exts = [".html", ".md", ".txt", ".pdf", ""]
|
||||
|
||||
dtformat = "%Y-%m-%d %H:%M"
|
||||
update = open("date", encoding="UTF-8").readline()
|
||||
tijden = Markup(
|
||||
markdown("".join(open("data/tijden.md", encoding="UTF-8").readlines())))
|
||||
nieuws = Markup(
|
||||
markdown("".join(open("data/nieuws.md", encoding="UTF-8").readlines())))
|
||||
renders = dict()
|
||||
|
||||
|
||||
@app.context_processor
|
||||
def inject_now():
|
||||
return {'now': datetime.utcnow(),
|
||||
'tijden': Markup(markdown("".join(open("data/tijden.md", encoding="UTF-8").readlines()))),
|
||||
'nieuws': Markup(markdown("".join(open("data/nieuws.md", encoding="UTF-8").readlines())))}
|
||||
return {'now': datetime.utcnow().year,
|
||||
'tijden': tijden,
|
||||
'nieuws': nieuws,
|
||||
'update': update}
|
||||
|
||||
|
||||
def render(filename):
|
||||
if filename in renders:
|
||||
return renders[filename]
|
||||
else:
|
||||
ren = Markup(markdown(
|
||||
"".join(open("data/"+filename, encoding="UTF-8").readlines())))
|
||||
renders[filename] = ren
|
||||
return ren
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
path = Path("data.json")
|
||||
if path.exists():
|
||||
with open('data.json') as f:
|
||||
try:
|
||||
data = json.load(f)
|
||||
print(data)
|
||||
|
||||
toload = data["default"]
|
||||
for time in data["list"]:
|
||||
print(time)
|
||||
dt = datetime.strptime(time, dtformat)
|
||||
if dt < datetime.now():
|
||||
toload = data["list"][time]
|
||||
|
||||
return render_template("index.html",
|
||||
content=markdown("".join(open("data/" + toload, encoding="UTF-8").readlines())))
|
||||
|
||||
except json.decoder.JSONDecodeError:
|
||||
pass
|
||||
|
||||
return render_template("index.html",
|
||||
content=markdown("".join(open("data/content.md", encoding="UTF-8").readlines())))
|
||||
return render_template("index.html", content=render("content.md"))
|
||||
|
||||
|
||||
@app.route("/<string:url>")
|
||||
|
@ -57,21 +52,19 @@ def site(url: str):
|
|||
if url.endswith(".html"):
|
||||
return redirect(url.rstrip(".html"), 301)
|
||||
|
||||
if url.endswith(".png") or url.endswith(".xml") or url.endswith(".json") or url.endswith(".ico"):
|
||||
if url.endswith(".ico"):
|
||||
return send_from_directory("static", url)
|
||||
|
||||
# actual code
|
||||
if url == "content":
|
||||
return redirect("/", 301)
|
||||
if exists("data/" + url.lstrip("/") + ".md"):
|
||||
filename = "data/" + url.lstrip("/") + ".md"
|
||||
filename = url.lstrip("/") + ".md"
|
||||
else:
|
||||
filename = "data/404.md"
|
||||
filename = "404.md"
|
||||
|
||||
return render_template("index.html",
|
||||
content=Markup(markdown("".join(open(filename, encoding="UTF-8").readlines()),
|
||||
use_file_vars=True,
|
||||
extras=["use-file-vars", "tables"])))
|
||||
content=render(filename))
|
||||
|
||||
|
||||
@app.route("/archief/<string:url>")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div style="margin-top: 0px; height: 69px;" id="container-footer">
|
||||
<div id="footer">
|
||||
<div style="margin-top: 14px; height: 14px;" id="footer-copyright">© {{ now.year }} Galerie van Slagmaat | <a
|
||||
<div style="margin-top: 14px; height: 14px;" id="footer-copyright">© {{ now }} Galerie van Slagmaat | <a
|
||||
href="/">home</a></div>
|
||||
</div>
|
||||
</div>
|
|
@ -1,13 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="nl">
|
||||
<head>
|
||||
{% include "common_head.html" %}
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
{% include "common_index.html" %}
|
||||
<div style="margin-top: 13px; {#height: 1164px;#}" id="container-content">
|
||||
<div style="margin-top: 0px;{# height: 1115px;#}" id="content">
|
||||
<div style="margin-top: 13px; " id="container-content">
|
||||
<div style="margin-top: 0px;" id="content">
|
||||
{{ content|safe }}
|
||||
</div>
|
||||
{% if request.path == "/" %}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
tel. 06 487 29 544 <br/>
|
||||
<a title="blocked::mailto:mariette@galerievanslagmaat.nl" href="mailto:mariette@galerievanslagmaat.nl">
|
||||
<span title="blocked::mailto:mariette@galerievanslagmaat.nl">
|
||||
<span style="">
|
||||
<span>
|
||||
<span style="color: rgb(102, 51, 102);">mariette@galerievanslagmaat.nl</span>
|
||||
</span>
|
||||
</span>
|
||||
|
@ -37,7 +37,7 @@
|
|||
style="font-weight: bold; color: rgb(102, 0, 102);">nieuwsbrief</span>? <br/>Mail "GRAAG" naar: <a
|
||||
title="blocked::mailto:mariette@galerievanslagmaat.nl"
|
||||
href="mailto:mariette@galerievanslagmaat.nl"><span
|
||||
title="blocked::mailto:mariette@galerievanslagmaat.nl"><span style=""><span
|
||||
title="blocked::mailto:mariette@galerievanslagmaat.nl"><span><span
|
||||
style="color: rgb(102, 51, 102);">mariette@galerievanslagmaat.nl</span></span></span></a></span><br/>
|
||||
</p>
|
||||
<hr style="height: 2px;"/>
|
||||
|
@ -53,7 +53,7 @@
|
|||
|
||||
<hr style="height: 2px;"/>
|
||||
<p style="margin-top: 16px; height: 40px;">Laatste
|
||||
update: 06-06-2019<br/>
|
||||
update: {{ update }}<br/>
|
||||
Webmaster: <a href="mailto:webmaster@galerievanslagmaat.nl?SUBJECT=Website Galerie van Slagmaat">Julius de
|
||||
Jeu</a>
|
||||
|
||||
|
|
Loading…
Reference in a new issue