feat: overview

This commit is contained in:
Hazel 2025-04-10 17:03:00 +02:00
parent b1a4d8e6ae
commit 4b307d7896

View File

@ -68,7 +68,7 @@ class Context:
def convert_md(src: Path, dst: Path, context: Optional[Context] = None): def convert_md(src: Path, dst: Path, context: Optional[Context] = None):
html_content = markdown.markdown(src.read_text()) html_content = markdown.markdown(src.read_text())
context = Context(str(src.parent)) context = context or Context(str(src.parent))
full_page = context.get_text(content=html_content) full_page = context.get_text(content=html_content)
folder_dst = dst.parent / dst.name.replace(".md", "") folder_dst = dst.parent / dst.name.replace(".md", "")
@ -89,16 +89,21 @@ class CustomLanguageCode:
@property @property
def relative_url(self) -> str: def relative_url(self) -> str:
return str(self.file) return "/" + str(Path(self.file.parent, self.language_code))
def __repr__(self) -> str: def __repr__(self) -> str:
return f"{self.language_code}" return f"{self.language_code}"
@property
def html_code(self) -> str:
return f'<ul><a href="{self.relative_url}"><bold>{self.language_code}</bold></a></ul>'
def walk_directory(root): def walk_directory(root):
src_path = Path(SOURCE_DIRECTORY, root) src_path = Path(SOURCE_DIRECTORY, root)
dst_path = Path(DIST_DIRECTORY, root) dst_path = Path(DIST_DIRECTORY, root)
context = Context(src_path)
language_codes_found = [] language_codes_found = []
for current_full_path in src_path.iterdir(): for current_full_path in src_path.iterdir():
@ -111,7 +116,7 @@ def walk_directory(root):
continue continue
if current_name.endswith(".md"): if current_name.endswith(".md"):
convert_md(current_src, current_dst) convert_md(current_src, current_dst, context=context)
language_codes_found.append(CustomLanguageCode(Path(root, current_name))) language_codes_found.append(CustomLanguageCode(Path(root, current_name)))
continue continue
@ -119,7 +124,13 @@ def walk_directory(root):
if current_src.is_dir(): if current_src.is_dir():
walk_directory(Path(root, current_full_path.name)) walk_directory(Path(root, current_full_path.name))
print(language_codes_found) content = f"""
<li>
{''.join(l.html_code for l in language_codes_found)}
</li>
"""
with Path(dst_path, "index.html").open("w") as f:
f.write(context.get_text(content=content))
def build(): def build():