summaryrefslogtreecommitdiff
path: root/pages.py
diff options
context:
space:
mode:
Diffstat (limited to 'pages.py')
-rw-r--r--pages.py84
1 files changed, 81 insertions, 3 deletions
diff --git a/pages.py b/pages.py
index f114be7..9f37762 100644
--- a/pages.py
+++ b/pages.py
@@ -11,14 +11,18 @@ 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"
+PATH_HTML_VIDEO_TEMPLATE = "./templates/video.html"
+PATH_VIDEO_INDEX = "./data/videos.json"
HTML_PROJECT_TEMPLATE = """"""
HTML_BLOGPOST_TEMPLATE = """"""
HTML_EVENT_TEMPLATE = """"""
+HTML_VIDEO_TEMPLATE = """"""
PROJECT_INDEX = {}
BLOGPOST_INDEX = {}
EVENT_INDEX = {}
+VIDEO_INDEX = {}
with open(PATH_HTML_PROJECT_TEMPLATE) as f:
@@ -27,6 +31,8 @@ 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_HTML_VIDEO_TEMPLATE) as f:
+ HTML_VIDEO_TEMPLATE = f.read()
with open(PATH_PROJECT_INDEX) as f:
PROJECT_INDEX = json.load(f)
@@ -34,6 +40,8 @@ with open(PATH_BLOGPOST_INDEX) as f:
BLOGPOST_INDEX = json.load(f)
with open(PATH_EVENT_INDEX) as f:
EVENT_INDEX = json.load(f)
+with open(PATH_VIDEO_INDEX) as f:
+ VIDEO_INDEX = json.load(f)
def render_project_details(project_name: str) -> tuple:
@@ -49,7 +57,7 @@ def render_project_details(project_name: str) -> tuple:
metadata, rendered_content = markdown_renderer.md_to_html(source)
print(metadata, rendered_content)
- html = html.replace("{[{content}]}", f"{rendered_content}")
+ html = html.replace("{[{content}]}", rendered_content)
if "logo" in metadata:
html = html.replace("{[{img-src-icon-bottom-bar}]}", metadata["logo"])
@@ -89,9 +97,79 @@ def render_project_details(project_name: str) -> tuple:
return (200, str(soup))
-def render_blogpost(blogpost_id: int):
- return (209, "")
+def render_blogpost(blogpost_id: int) -> tuple:
+ html = HTML_BLOGPOST_TEMPLATE
+ source = ""
+
+ if blogpost_id >= len(BLOGPOST_INDEX["posts"]):
+ return (404, "")
+
+ metadata = BLOGPOST_INDEX["posts"][blogpost_id]
+
+ with open("." + metadata["path"], "r") as f:
+ source = f.read()
+
+ _, rendered_content = markdown_renderer.md_to_html(source)
+ print(metadata, rendered_content)
+
+ html = html.replace("{[{content}]}", rendered_content)
+
+ soup = BeautifulSoup(html, "html.parser")
+ soup.title.string = soup.title.string.replace("{[{title}]}", metadata["title"])
+
+ soup.select_one("#banner")["src"] = metadata["banner"]
+ soup.select_one("#title").string = metadata["title"]
+ soup.select_one("#description").string = metadata["description"]
+ soup.select_one("#date").string = metadata["date"]
+ soup.select_one("#author").string = metadata["author"]
+
+ for tag in metadata["tags"]:
+ new_tag = soup.new_tag("span")
+ new_tag["class"] = "chip"
+ new_tag.string = tag
+ soup.select_one("#tag-container").append(new_tag)
+
+ return (200, str(soup))
def blog_list() -> dict:
return BLOGPOST_INDEX
+
+
+def render_video(video_name: str) -> tuple:
+ html = HTML_VIDEO_TEMPLATE
+ source = ""
+
+ if video_name not in VIDEO_INDEX:
+ return (404, "")
+
+ with open("." + VIDEO_INDEX[video_name]["content_path"], "r") as f:
+ source = f.read()
+
+ metadata, rendered_content = markdown_renderer.md_to_html(source)
+ metadata["path"] = VIDEO_INDEX[video_name]["path"]
+ print(metadata, rendered_content)
+
+ html = html.replace("{[{content}]}", rendered_content)
+
+ html = html.replace("{[{video-title}]}", metadata["title"])
+ html = html.replace("{[{description}]}", metadata["description"])
+ html = html.replace("{[{date}]}", metadata["date"])
+
+ soup = BeautifulSoup(html, "html.parser")
+ soup.title.string = soup.title.string.replace("{[{title}]}", metadata["title"])
+
+ soup.select_one("#video")["src"] = metadata["path"]
+
+ if metadata["default_copyright"]:
+ soup.select_one("#video-license-parent").string = "©️ All rights reserved"
+ else:
+ soup.select_one("#video-license-info")["href"] = metadata["license_url"]
+ soup.select_one("#video-license-info").insert(0, BeautifulSoup(metadata["license"], "html.parser"))
+
+ if metadata["downloadable"] and not metadata["default_copyright"]:
+ soup.select_one("#video-download-btn").href = metadata["path"]
+ else:
+ soup.select_one("#video-download-btn").decompose()
+
+ return (200, str(soup))