updated to render md from content dir

This commit is contained in:
venus
2026-03-04 18:00:42 -06:00
parent 6c6cccae49
commit 62dcfab912
4 changed files with 44 additions and 39 deletions

View File

@@ -1,35 +1,23 @@
from flask import Flask
import markdown
from app import build
from pathlib import Path
import markdown
app = Flask(__name__)
CONTENT_DIR = Path(__file__).parent.parent / "content"
@app.route("/hello")
def hello_world():
return "<h1>Hello, World!</h1>"
CONTENT_DIR = Path("/content")
@app.route("/")
def index():
# Write your markdown content
md_content = "# Welcome to my blog!\nThis is rendered from **Markdown**."
md_content = "# Welcome to my blog!\nThis is rendered from **Markdown**.\n##[test](http://localhost/test)"
# Convert it to HTML
html_content = markdown.markdown(md_content)
return html_content
@app.route ("/post/<filename>")
def render_markdown_file(filename):
filePath = CONTENT_DIR / f"{filename}.md"
# 3. Protect against missing files
if not filePath.is_file():
return f"<h1>404</h1><p>Could not find {filename}.md in {filePath}</p>", 404
# else:
# return f"<h1> found</h1> <p> found {filename} in {filePath}</p>"
# 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
@app.route ("/<filename>")
def render_post(filename):
return build.render_file(filename, CONTENT_DIR)
# return "test"
# return rm(filename)