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
|
COPY . /app
|
||||||
|
|
||||||
|
RUN date +%d-%m-%Y > /app/date
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
EXPOSE 8000
|
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", ""]
|
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
|
@app.context_processor
|
||||||
def inject_now():
|
def inject_now():
|
||||||
return {'now': datetime.utcnow(),
|
return {'now': datetime.utcnow().year,
|
||||||
'tijden': Markup(markdown("".join(open("data/tijden.md", encoding="UTF-8").readlines()))),
|
'tijden': tijden,
|
||||||
'nieuws': Markup(markdown("".join(open("data/nieuws.md", encoding="UTF-8").readlines())))}
|
'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('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
path = Path("data.json")
|
return render_template("index.html", content=render("content.md"))
|
||||||
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())))
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/<string:url>")
|
@app.route("/<string:url>")
|
||||||
|
@ -57,21 +52,19 @@ def site(url: str):
|
||||||
if url.endswith(".html"):
|
if url.endswith(".html"):
|
||||||
return redirect(url.rstrip(".html"), 301)
|
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)
|
return send_from_directory("static", url)
|
||||||
|
|
||||||
# actual code
|
# actual code
|
||||||
if url == "content":
|
if url == "content":
|
||||||
return redirect("/", 301)
|
return redirect("/", 301)
|
||||||
if exists("data/" + url.lstrip("/") + ".md"):
|
if exists("data/" + url.lstrip("/") + ".md"):
|
||||||
filename = "data/" + url.lstrip("/") + ".md"
|
filename = url.lstrip("/") + ".md"
|
||||||
else:
|
else:
|
||||||
filename = "data/404.md"
|
filename = "404.md"
|
||||||
|
|
||||||
return render_template("index.html",
|
return render_template("index.html",
|
||||||
content=Markup(markdown("".join(open(filename, encoding="UTF-8").readlines()),
|
content=render(filename))
|
||||||
use_file_vars=True,
|
|
||||||
extras=["use-file-vars", "tables"])))
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/archief/<string:url>")
|
@app.route("/archief/<string:url>")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div style="margin-top: 0px; height: 69px;" id="container-footer">
|
<div style="margin-top: 0px; height: 69px;" id="container-footer">
|
||||||
<div id="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>
|
href="/">home</a></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -1,13 +1,13 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="nl">
|
||||||
<head>
|
<head>
|
||||||
{% include "common_head.html" %}
|
{% include "common_head.html" %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{% include "common_index.html" %}
|
{% include "common_index.html" %}
|
||||||
<div style="margin-top: 13px; {#height: 1164px;#}" id="container-content">
|
<div style="margin-top: 13px; " id="container-content">
|
||||||
<div style="margin-top: 0px;{# height: 1115px;#}" id="content">
|
<div style="margin-top: 0px;" id="content">
|
||||||
{{ content|safe }}
|
{{ content|safe }}
|
||||||
</div>
|
</div>
|
||||||
{% if request.path == "/" %}
|
{% if request.path == "/" %}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
tel. 06 487 29 544 <br/>
|
tel. 06 487 29 544 <br/>
|
||||||
<a title="blocked::mailto:mariette@galerievanslagmaat.nl" href="mailto:mariette@galerievanslagmaat.nl">
|
<a title="blocked::mailto:mariette@galerievanslagmaat.nl" href="mailto:mariette@galerievanslagmaat.nl">
|
||||||
<span title="blocked::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 style="color: rgb(102, 51, 102);">mariette@galerievanslagmaat.nl</span>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
style="font-weight: bold; color: rgb(102, 0, 102);">nieuwsbrief</span>? <br/>Mail "GRAAG" naar: <a
|
style="font-weight: bold; color: rgb(102, 0, 102);">nieuwsbrief</span>? <br/>Mail "GRAAG" naar: <a
|
||||||
title="blocked::mailto:mariette@galerievanslagmaat.nl"
|
title="blocked::mailto:mariette@galerievanslagmaat.nl"
|
||||||
href="mailto:mariette@galerievanslagmaat.nl"><span
|
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/>
|
style="color: rgb(102, 51, 102);">mariette@galerievanslagmaat.nl</span></span></span></a></span><br/>
|
||||||
</p>
|
</p>
|
||||||
<hr style="height: 2px;"/>
|
<hr style="height: 2px;"/>
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
|
|
||||||
<hr style="height: 2px;"/>
|
<hr style="height: 2px;"/>
|
||||||
<p style="margin-top: 16px; height: 40px;">Laatste
|
<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
|
Webmaster: <a href="mailto:webmaster@galerievanslagmaat.nl?SUBJECT=Website Galerie van Slagmaat">Julius de
|
||||||
Jeu</a>
|
Jeu</a>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue