From 64b42b2f7b91d4d4554626ab63e6fcd4174a9592 Mon Sep 17 00:00:00 2001 From: Niklas Elsbrock Date: Thu, 7 May 2026 01:36:08 +0200 Subject: [PATCH] use jinja to statically build website --- .gitignore | 1 + build.py | 56 ++++++++++++++++++ licenses.html | 55 ----------------- privacy.html | 48 --------------- .../hu/dizb37aqa5h4skgu7jf1xjr4q71w4paq | Bin .../.well-known}/openpgpkey/policy | 0 index.html => src/_base.html.jinja | 21 +------ src/index.html.jinja | 20 +++++++ src/licenses.html.jinja | 34 +++++++++++ .../niklas_elsbrock.asc | 0 src/privacy.html.jinja | 27 +++++++++ .../resources}/fonts/fontawesome/LICENSE.txt | 0 .../fonts/fontawesome/fa-brands-400.woff2 | Bin .../fonts/fontawesome/fa-solid-900.woff2 | Bin .../resources}/fonts/inter/Inter-Bold.woff2 | Bin .../resources}/fonts/inter/Inter-Italic.woff2 | Bin .../fonts/inter/Inter-Regular.woff2 | Bin .../resources}/fonts/inter/LICENSE.txt | 0 .../fonts/metropolis/Metropolis-Bold.woff2 | Bin .../fonts/metropolis/Metropolis-Regular.woff2 | Bin .../metropolis/Metropolis-RegularItalic.woff2 | Bin .../resources}/fonts/metropolis/UNLICENSE | 0 {resources => src/resources}/style.css | 0 robots.txt => src/robots.txt | 0 24 files changed, 141 insertions(+), 121 deletions(-) create mode 100644 .gitignore create mode 100755 build.py delete mode 100644 licenses.html delete mode 100644 privacy.html rename {.well-known => src/.well-known}/openpgpkey/hu/dizb37aqa5h4skgu7jf1xjr4q71w4paq (100%) rename {.well-known => src/.well-known}/openpgpkey/policy (100%) rename index.html => src/_base.html.jinja (52%) create mode 100644 src/index.html.jinja create mode 100644 src/licenses.html.jinja rename niklas_elsbrock.asc => src/niklas_elsbrock.asc (100%) create mode 100644 src/privacy.html.jinja rename {resources => src/resources}/fonts/fontawesome/LICENSE.txt (100%) rename {resources => src/resources}/fonts/fontawesome/fa-brands-400.woff2 (100%) rename {resources => src/resources}/fonts/fontawesome/fa-solid-900.woff2 (100%) rename {resources => src/resources}/fonts/inter/Inter-Bold.woff2 (100%) rename {resources => src/resources}/fonts/inter/Inter-Italic.woff2 (100%) rename {resources => src/resources}/fonts/inter/Inter-Regular.woff2 (100%) rename {resources => src/resources}/fonts/inter/LICENSE.txt (100%) rename {resources => src/resources}/fonts/metropolis/Metropolis-Bold.woff2 (100%) rename {resources => src/resources}/fonts/metropolis/Metropolis-Regular.woff2 (100%) rename {resources => src/resources}/fonts/metropolis/Metropolis-RegularItalic.woff2 (100%) rename {resources => src/resources}/fonts/metropolis/UNLICENSE (100%) rename {resources => src/resources}/style.css (100%) rename robots.txt => src/robots.txt (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e22129 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist \ No newline at end of file diff --git a/build.py b/build.py new file mode 100755 index 0000000..229a7c1 --- /dev/null +++ b/build.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +import contextlib +from io import BufferedWriter, FileIO +import os +import shutil +import git +from jinja2 import Environment, FileSystemLoader + +SOURCES_DIR = "src" +DIST_DIR = "dist" + +def latest_git_commit_year() -> int: + return git.Repo(".").head.commit.authored_datetime.year + +def build_template(env: Environment, src_path: str): + rel_path = os.path.relpath(src_path, SOURCES_DIR) + dist_path = os.path.splitext(os.path.join(DIST_DIR, rel_path))[0] + + template = env.get_template(rel_path) + rendered_text = template.render(copyright_year = latest_git_commit_year()) + + with BufferedWriter(FileIO(dist_path, "wb")) as writer: + for line in rendered_text.splitlines(): + line = line.strip() + if len(line) > 0: + writer.write(line.encode()) + writer.write(b"\n") + +env = Environment( + loader=FileSystemLoader(SOURCES_DIR), + autoescape=True +) + +def main(): + with contextlib.suppress(FileNotFoundError): + shutil.rmtree(DIST_DIR) + + for root, _, files in os.walk(SOURCES_DIR): + rel_dir_path = os.path.relpath(root, SOURCES_DIR) + dist_root = os.path.join(DIST_DIR, rel_dir_path) + os.makedirs(dist_root, exist_ok=True) + + for src_name in files: + src_path = os.path.join(root, src_name) + + if src_name.endswith(".jinja"): + if not src_name.startswith("_"): + build_template(env, src_path) + + else: + dist_path = os.path.join(dist_root, src_name) + shutil.copy(src_path, dist_path) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/licenses.html b/licenses.html deleted file mode 100644 index ef9e536..0000000 --- a/licenses.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - Niklas Elsbrock – Open-Source-Lizenzen - - - - - - - -
-
-

Open-Source-Lizenzen

- -

Schriftarten:

- -

Überschriften: Metropolis

-

Public Domain (Unlicense)

- -

Text: Inter

-

- Copyright (c) 2016-2020 The Inter Project Authors.
- "Inter" is trademark of Rasmus Andersson.
- Licensed under the SIL Open Font License, Version 1.1. -

- -

Icons: Font Awesome Free

-

- Copyright (c) 2024 Fonticons, Inc.
- with Reserved Font Name: "Font Awesome".
- Licensed under the SIL Open Font License, Version 1.1. -

- -
- -

- Zurück zur Hauptseite -

-
-
- - - diff --git a/privacy.html b/privacy.html deleted file mode 100644 index 1547dba..0000000 --- a/privacy.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - Niklas Elsbrock – Datenschutz - - - - - - - -
-
-

Datenschutz

-

Verantwortlich für diese Website ist

-
- Niklas Elsbrock
- mail@nelsbrock.de -
- -

Keine Erfassung von Besucherinformationen

-

- Beim Besuch der Website unter www.nelsbrock.de werden keine - personenbezogenen Daten verarbeitet. Zugriffsprotokolle sind - deaktiviert. -

- -
- -

- Zurück zur Hauptseite -

-
-
- - - diff --git a/.well-known/openpgpkey/hu/dizb37aqa5h4skgu7jf1xjr4q71w4paq b/src/.well-known/openpgpkey/hu/dizb37aqa5h4skgu7jf1xjr4q71w4paq similarity index 100% rename from .well-known/openpgpkey/hu/dizb37aqa5h4skgu7jf1xjr4q71w4paq rename to src/.well-known/openpgpkey/hu/dizb37aqa5h4skgu7jf1xjr4q71w4paq diff --git a/.well-known/openpgpkey/policy b/src/.well-known/openpgpkey/policy similarity index 100% rename from .well-known/openpgpkey/policy rename to src/.well-known/openpgpkey/policy diff --git a/index.html b/src/_base.html.jinja similarity index 52% rename from index.html rename to src/_base.html.jinja index 4560f72..4468ff1 100644 --- a/index.html +++ b/src/_base.html.jinja @@ -1,11 +1,9 @@ - - - Niklas Elsbrock + {% block title %}{% endblock %} @@ -14,24 +12,11 @@
-
-
-

Niklas Elsbrock

-

Softwareentwickler und Informatikstudent

-
-
- -
+ {% block main %}{% endblock %}