from flask import Flask import markdown from pathlib import Path app = Flask(__name__) CONTENT_DIR = Path(__file__).parent.parent / "content" @app.route("/hello") def hello_world(): return "

Hello, World!

" @app.route("/") def index(): # Write your markdown content md_content = "# Welcome to my blog!\nThis is rendered from **Markdown**." # Convert it to HTML html_content = markdown.markdown(md_content) return html_content @app.route ("/post/") def render_markdown_file(filename): filePath = CONTENT_DIR / f"{filename}.md" # 3. Protect against missing files if not filePath.is_file(): return f"

404

Could not find {filename}.md in {filePath}

", 404 # else: # return f"

found

found {filename} in {filePath}

" # 4. Open, read, and convert the file with open(filePath, "r", encoding="utf-8") as f: textContent = f.read() htmlContent = markdown.markdown(textContent) return htmlContent