diff --git a/stsg/build.py b/stsg/build.py index 54ebe69..dff4863 100644 --- a/stsg/build.py +++ b/stsg/build.py @@ -68,7 +68,7 @@ class Context: def convert_md(src: Path, dst: Path, context: Optional[Context] = None): 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) folder_dst = dst.parent / dst.name.replace(".md", "") @@ -89,16 +89,21 @@ class CustomLanguageCode: @property def relative_url(self) -> str: - return str(self.file) + return "/" + str(Path(self.file.parent, self.language_code)) def __repr__(self) -> str: return f"{self.language_code}" + @property + def html_code(self) -> str: + return f'' + def walk_directory(root): src_path = Path(SOURCE_DIRECTORY, root) dst_path = Path(DIST_DIRECTORY, root) + context = Context(src_path) language_codes_found = [] for current_full_path in src_path.iterdir(): @@ -111,7 +116,7 @@ def walk_directory(root): continue 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))) continue @@ -119,7 +124,13 @@ def walk_directory(root): if current_src.is_dir(): walk_directory(Path(root, current_full_path.name)) - print(language_codes_found) + content = f""" +
  • + {''.join(l.html_code for l in language_codes_found)} +
  • + """ + with Path(dst_path, "index.html").open("w") as f: + f.write(context.get_text(content=content)) def build():