Skip to content

Commit

Permalink
feat: add index page
Browse files Browse the repository at this point in the history
Closes #1.
  • Loading branch information
m0wer committed May 9, 2024
1 parent 16c213a commit dfb183b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/modules/site_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,34 @@ def render_site(self, site: dict) -> None:
with open(site_path / "index.html", "w") as f:
f.write(rendered)

def create_index_page(self, conf) -> None:
index_html = f"""<html>
<head>
<title>Idea projects</title>
</head>
<body>
<h1>All projects</h1>
<ul>
{"".join([
f'<li><a href="{site["page_identifier"]}/">{site["title"]}</a>: {site["description"]}</li>'
for site in conf["sites"]
])}
</ul>
</body>
</html>"""

with open(self.static_pages_dir / "index.html", "w") as f:
f.write(index_html)

def render_sites(self) -> None:
with open(self.conf_path, "r") as conf_file:
conf = yaml.safe_load(conf_file)

for site in conf["sites"]:
self.render_site(site)

self.create_index_page(conf)


if __name__ == "__main__":
SiteRenderer(CONF_PATH, TEMPLATE_SRC, STATIC_PAGES_DIR).render_sites()

0 comments on commit dfb183b

Please sign in to comment.