diff options
| author | altaf-creator <dev@altafcreator.com> | 2026-05-17 13:01:57 +0800 |
|---|---|---|
| committer | altaf-creator <dev@altafcreator.com> | 2026-05-17 13:01:57 +0800 |
| commit | 9e7fe6d8dad56c237adb1905e130c1d723131812 (patch) | |
| tree | dd067e14b3ec5af719d748427bb322320c248879 /pages.py | |
| parent | d04598ba59d7267ee4db3745ff90eaa1a990072a (diff) | |
big structural change, altafcreator.com no longer served statically, projects now use md, blog is being reworked, videos removed temp
Diffstat (limited to 'pages.py')
| -rw-r--r-- | pages.py | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/pages.py b/pages.py new file mode 100644 index 0000000..f114be7 --- /dev/null +++ b/pages.py @@ -0,0 +1,97 @@ +from bs4 import BeautifulSoup +import json +from copy import copy + +import markdown_renderer # markdown_renderer.py + + +PATH_HTML_PROJECT_TEMPLATE = "./templates/project.html" +PATH_PROJECT_INDEX = "./data/projects.json" +PATH_HTML_BLOGPOST_TEMPLATE = "./templates/blogpost.html" +PATH_BLOGPOST_INDEX = "./data/blogs.json" +PATH_HTML_EVENT_TEMPLATE = "./templates/eventdetails.html" +PATH_EVENT_INDEX = "./data/events.json" + +HTML_PROJECT_TEMPLATE = """""" +HTML_BLOGPOST_TEMPLATE = """""" +HTML_EVENT_TEMPLATE = """""" + +PROJECT_INDEX = {} +BLOGPOST_INDEX = {} +EVENT_INDEX = {} + + +with open(PATH_HTML_PROJECT_TEMPLATE) as f: + HTML_PROJECT_TEMPLATE = f.read() +with open(PATH_HTML_BLOGPOST_TEMPLATE) as f: + HTML_BLOGPOST_TEMPLATE = f.read() +with open(PATH_HTML_EVENT_TEMPLATE) as f: + HTML_EVENT_TEMPLATE = f.read() + +with open(PATH_PROJECT_INDEX) as f: + PROJECT_INDEX = json.load(f) +with open(PATH_BLOGPOST_INDEX) as f: + BLOGPOST_INDEX = json.load(f) +with open(PATH_EVENT_INDEX) as f: + EVENT_INDEX = json.load(f) + + +def render_project_details(project_name: str) -> tuple: + html = HTML_PROJECT_TEMPLATE + source = "" + + if project_name not in PROJECT_INDEX: + return (404, "") + + with open("." + PROJECT_INDEX[project_name]["path"], "r") as f: + source = f.read() + + metadata, rendered_content = markdown_renderer.md_to_html(source) + print(metadata, rendered_content) + + html = html.replace("{[{content}]}", f"{rendered_content}") + if "logo" in metadata: + html = html.replace("{[{img-src-icon-bottom-bar}]}", metadata["logo"]) + + soup = BeautifulSoup(html, 'html.parser') + + soup.title.string = soup.title.string.replace("{[{title}]}", metadata["title"]) + soup.find("section", "banner-section")["id"] = metadata["bannerId"] + for platform in ["win", "mac", "lin", "web"]: + if platform not in metadata["platforms"]: + soup.select_one(f"#compatible-{platform}").decompose() + + if "trailerPath" not in metadata: + soup.select_one("#video-play-btn").decompose() + soup.select_one("#video").decompose() + else: + soup.select_one("#video")["src"] = metadata["trailerPath"] + + for action in metadata["actions"]: + new_btn = soup.new_tag("a") + new_btn["class"] = "button button-inline" + new_btn["href"] = action["url"] + new_btn_icon = soup.new_tag("i") + new_btn_icon["class"] = action["icon"] + new_btn.append(new_btn_icon) + new_btn.append(f' {action["text"]}') + + if action["mode"] == "mobile": + new_btn["class"] += " mobile" + if action["mode"] == "desktop": + new_btn["class"] += " desktop" + + if action["bannerBar"]: + soup.select_one("#banner-actions-bar").append(new_btn) + if action["bottomBar"]: + soup.select_one("#bottom-bar").insert(0, copy(new_btn)) + + return (200, str(soup)) + + +def render_blogpost(blogpost_id: int): + return (209, "") + + +def blog_list() -> dict: + return BLOGPOST_INDEX |
