From d163092b5c159ddd1813550d1f9bab72adbdf80a Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Fri, 31 Jul 2026 20:57:25 +0800 Subject: index and blog is now ssr --- pages.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'pages.py') 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"{tag}" + + snippet = f""" +
+ +
+
+ {evaluatedTags} +
+

{post["title"]}

+

{post["date"]}

+

{post["description"]}

+
+
+ """ + + return BeautifulSoup(snippet, "html.parser") -- cgit v1.2.3