summaryrefslogtreecommitdiff
path: root/pages.py
diff options
context:
space:
mode:
authoraltaf-creator <dev@altafcreator.com>2026-07-31 20:57:25 +0800
committeraltaf-creator <dev@altafcreator.com>2026-07-31 20:57:25 +0800
commitd163092b5c159ddd1813550d1f9bab72adbdf80a (patch)
treed30657c2aa127a57ff58a267a502aa0e3f7378c6 /pages.py
parentf1966a70cd5bdcb606c579d5146e26acfc1028fc (diff)
index and blog is now ssr
Diffstat (limited to 'pages.py')
-rw-r--r--pages.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/pages.py b/pages.py
index e204a3e..04c1671 100644
--- a/pages.py
+++ b/pages.py
@@ -13,11 +13,15 @@ PATH_HTML_EVENT_TEMPLATE = "./templates/eventdetails.html"
PATH_EVENT_INDEX = "./data/events.json"
PATH_HTML_VIDEO_TEMPLATE = "./templates/video.html"
PATH_VIDEO_INDEX = "./data/videos.json"
+PATH_INDEX = "./www/index.html"
+PATH_BLOGLIST = "./www/blog/index.html"
HTML_PROJECT_TEMPLATE = """"""
HTML_BLOGPOST_TEMPLATE = """"""
HTML_EVENT_TEMPLATE = """"""
HTML_VIDEO_TEMPLATE = """"""
+HTML_INDEX = """"""
+HTML_BLOGLIST = """"""
PROJECT_INDEX = {}
BLOGPOST_INDEX = {}
@@ -34,6 +38,10 @@ with open(PATH_HTML_EVENT_TEMPLATE) as f:
HTML_EVENT_TEMPLATE = f.read()
with open(PATH_HTML_VIDEO_TEMPLATE) as f:
HTML_VIDEO_TEMPLATE = f.read()
+with open(PATH_INDEX) as f:
+ HTML_INDEX = f.read()
+with open(PATH_BLOGLIST) as f:
+ HTML_BLOGLIST = f.read()
with open(PATH_PROJECT_INDEX) as f:
PROJECT_INDEX = json.load(f)
@@ -234,3 +242,55 @@ def render_event(event_name: str) -> tuple:
soup.title.string = soup.title.string.replace("{[{title}]}", metadata["title"])
return (200, str(soup))
+
+
+def render_index() -> tuple:
+ html = HTML_INDEX
+
+ soup = BeautifulSoup(html, "html.parser")
+
+ soup.select_one("#blog-container").append(render_blogpost_card(len(BLOGPOST_INDEX["posts"]) - 1))
+ soup.select_one("#blog-container").append(render_blogpost_card(len(BLOGPOST_INDEX["posts"]) - 2))
+
+ return (200, soup)
+
+
+def render_blog_list() -> tuple:
+ html = HTML_BLOGLIST
+
+ soup = BeautifulSoup(html, "html.parser")
+
+ for i in range(len(BLOGPOST_INDEX["posts"]) - 1, -1, -1):
+ soup.select_one("#blog-container").append(render_blogpost_card(i))
+
+ return (200, soup)
+
+
+def render_blogpost_card(idx: int) -> BeautifulSoup:
+ if idx >= len(BLOGPOST_INDEX["posts"]):
+ print(f"blog of index {idx} doesn't exist")
+ return None
+
+ post = BLOGPOST_INDEX["posts"][idx]
+
+ evaluatedTags = ""
+
+ for tag in post["tags"]:
+ evaluatedTags += f"<span class=\"chip\">{tag}</span>"
+
+ snippet = f"""
+ <div class="card" tabindex="9999">
+ <img src="{post["thumbnail"]}"
+ alt="">
+ <div>
+ <div class="flex-container-normal chip-container">
+ {evaluatedTags}
+ </div>
+ <a href="/blog/{idx}" class="link"><h2>{post["title"]}</h2></a>
+ <p class="half-opacity-text"><i class="fa-solid fa-calendar"></i> {post["date"]}</p>
+ <p>{post["description"]}</p>
+ </div>
+ </div>
+ """
+
+ return BeautifulSoup(snippet, "html.parser")