Files
LifeFaq/depricated/markdown_service.py

26 lines
1.1 KiB
Python
Raw Normal View History

2024-12-11 20:34:20 +01:00
import os
2024-12-11 23:56:15 +01:00
from app.services.markdown_render import render_markdown_with_jinja
2024-12-11 20:34:20 +01:00
def process_markdown_files(input_dir: str, output_dir: str):
"""
Recursively process all Markdown files in the input directory,
2024-12-11 23:56:15 +01:00
render them to HTML, and save them in the output directory.
2024-12-11 20:34:20 +01:00
"""
for root, _, files in os.walk(input_dir):
for file in files:
if file.endswith(".md"):
input_file_path = os.path.join(root, file)
relative_path = os.path.relpath(input_file_path, input_dir)
output_file_path = os.path.join(output_dir, os.path.splitext(relative_path)[0] + ".html")
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
with open(input_file_path, "r", encoding="utf-8") as md_file:
markdown_content = md_file.read()
print(f"Processing: {input_file_path} -> {output_file_path}")
rendered_html = render_markdown_with_jinja(markdown_content)
with open(output_file_path, "w", encoding="utf-8") as html_file:
html_file.write(rendered_html)