From 71949c087bed66f41850801365bfb9dc373292d9 Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Sat, 8 Jun 2019 19:54:47 +0200 Subject: [PATCH] Add build date generation. Add render caching to make it less heavy on the filesystem, should speed site up somehow... --- Dockerfile | 2 ++ app.py | 57 ++++++++++++++++++------------------------ date | 1 + templates/footer.html | 2 +- templates/index.html | 6 ++--- templates/sidebar.html | 6 ++--- 6 files changed, 35 insertions(+), 39 deletions(-) create mode 100644 date diff --git a/Dockerfile b/Dockerfile index 9be9c14..c64defa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,8 @@ COPY --from=builder /install /usr/local COPY . /app +RUN date +%d-%m-%Y > /app/date + WORKDIR /app EXPOSE 8000 diff --git a/app.py b/app.py index 9e24054..60917c6 100644 --- a/app.py +++ b/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("/") @@ -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/") diff --git a/date b/date new file mode 100644 index 0000000..4353596 --- /dev/null +++ b/date @@ -0,0 +1 @@ +goede vraag... \ No newline at end of file diff --git a/templates/footer.html b/templates/footer.html index a29198f..682c584 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 2b47b54..404d829 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,13 +1,13 @@ - + {% include "common_head.html" %}
{% include "common_index.html" %} -
-
+
+
{{ content|safe }}
{% if request.path == "/" %} diff --git a/templates/sidebar.html b/templates/sidebar.html index b125555..69b8325 100644 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -14,7 +14,7 @@ tel. 06 487 29 544
- + mariette@galerievanslagmaat.nl @@ -37,7 +37,7 @@ style="font-weight: bold; color: rgb(102, 0, 102);">nieuwsbrief?
Mail "GRAAG" naar:
mariette@galerievanslagmaat.nl


@@ -53,7 +53,7 @@

Laatste - update: 06-06-2019
+ update: {{ update }}
Webmaster: Julius de Jeu