From fab58de71df7a4fd6e24662d77622d462cef96e5 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 10 Apr 2025 14:43:37 +0200 Subject: [PATCH] feat: implemented context class --- src/index.html | 22 ++++++++ src/static/.hidden/dont_copy | 1 - src/static/.hidden/really_please_dont/foo | 0 src/static/.style.css | 66 ----------------------- src/static/assets/foo.bar | 1 - stsg/build.py | 35 +++++++++++- 6 files changed, 56 insertions(+), 69 deletions(-) delete mode 100644 src/static/.hidden/dont_copy delete mode 100644 src/static/.hidden/really_please_dont/foo delete mode 100644 src/static/.style.css delete mode 100644 src/static/assets/foo.bar diff --git a/src/index.html b/src/index.html index e69de29..2f52f77 100644 --- a/src/index.html +++ b/src/index.html @@ -0,0 +1,22 @@ + + + + + + Hello Bulma! + + + +
+
+

Hello World

+

My first website with Bulma!

+ + +
+
+ + diff --git a/src/static/.hidden/dont_copy b/src/static/.hidden/dont_copy deleted file mode 100644 index 0519ecb..0000000 --- a/src/static/.hidden/dont_copy +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/static/.hidden/really_please_dont/foo b/src/static/.hidden/really_please_dont/foo deleted file mode 100644 index e69de29..0000000 diff --git a/src/static/.style.css b/src/static/.style.css deleted file mode 100644 index 5d8f994..0000000 --- a/src/static/.style.css +++ /dev/null @@ -1,66 +0,0 @@ -/* styles.css */ - -/* Reset some default styles */ -* { - margin: 0; - padding: 0; - box-sizing: border-box; -} - -/* Body styles */ -body { - font-family: Arial, sans-serif; - line-height: 1.6; - background-color: #f5f5f5; - color: #333; - padding: 20px; -} - -/* Header styles */ -header { - background-color: #4a90e2; - color: white; - padding: 20px 0; - text-align: center; - border-radius: 8px; -} - -/* Navigation */ -nav ul { - list-style: none; - display: flex; - justify-content: center; - padding: 10px 0; -} - -nav ul li { - margin: 0 15px; -} - -nav ul li a { - text-decoration: none; - color: white; - font-weight: bold; -} - -/* Main content */ -main { - margin: 20px 0; -} - -/* Section styling */ -section { - margin-bottom: 20px; - padding: 20px; - background-color: white; - border-radius: 8px; - box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); -} - -/* Footer styles */ -footer { - text-align: center; - margin-top: 40px; - padding: 10px; - color: #777; -} diff --git a/src/static/assets/foo.bar b/src/static/assets/foo.bar deleted file mode 100644 index 30d74d2..0000000 --- a/src/static/assets/foo.bar +++ /dev/null @@ -1 +0,0 @@ -test \ No newline at end of file diff --git a/stsg/build.py b/stsg/build.py index b8c8759..8a947e3 100644 --- a/stsg/build.py +++ b/stsg/build.py @@ -39,9 +39,42 @@ def copy_static(): dest_file = os.path.join(dest_dir, file) shutil.copy2(src_file, dest_file) - print(src, dst) + +class Context: + def __init__(self, root: str = SOURCE_DIRECTORY): + self.file = Path(root, "index.html") + + current_root = Path(root) + while current_root.parts and self.file is None: + current_file = Path(current_root, "index.html") + if current_file.exists() and current_file.is_file: + self.file = current_file + + current_root = current_root.parent + + if self.file is None: + logger.error("couldn't find context for %s", root) + exit(1) + logger.info("%s found context %r", root, str(self.file)) + + def get_text(self, placeholder_values: dict): + text = self.file.read_text() + + for key, value in placeholder_values.items(): + text = text.replace(f"<{key}/>", value) + text = text.replace(f"<{key} />", value) + + return text def build(): logger.info("building static page") copy_static() + + context = Context() + print(context.get_text({ + "content": """ +

Hello World

+

My first website with Bulma!

+ """ + }))