From 62dcfab91254dc915b2f9d21c419da54c0dec19c Mon Sep 17 00:00:00 2001 From: venus Date: Wed, 4 Mar 2026 18:00:42 -0600 Subject: [PATCH] updated to render md from content dir --- Dockerfile | 1 + app/__init__.py | 32 ++++++++++-------------------- app/build.py | 47 ++++++++++++++++++++++++++++---------------- app/requirements.txt | 3 +++ 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/Dockerfile b/Dockerfile index 574fa44..68174db 100755 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ ENV FLASK_APP=app RUN mkdir /app COPY app/requirements.txt /app RUN pip3 install -r /app/requirements.txt + COPY app /app ENTRYPOINT ["flask"] diff --git a/app/__init__.py b/app/__init__.py index 321d5b5..b579650 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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 "

Hello, World!

" +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/") -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 +@app.route ("/") +def render_post(filename): + return build.render_file(filename, CONTENT_DIR) + # return "test" + + # return rm(filename) diff --git a/app/build.py b/app/build.py index fb829c5..8d04fc0 100644 --- a/app/build.py +++ b/app/build.py @@ -1,26 +1,39 @@ from obsidian_parser import Vault import shutil -from git import Repo +import markdown +from pathlib import Path +def render_file(filename: str, contentPath: Path): #renders markwown from filename + filePath = contentPath / f"{filename}.md" + # 3. Protect against missing files + if not filePath.is_file(): + return f"

404

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

", 404 + # open the file for reading + with open(filePath, "r", encoding="utf-8") as f: + textContent = f.read() + # convert it to markdown + htmlContent = markdown.markdown(textContent) + return htmlContent -def clone_secure_repo(url: str, token: str = "", dest: str): # clone a gittea repo using optional security token into dest dirand return a path to the directory - return dest +print("build imported") +# def clone_gittea_repo(url: str, token: str = "", dest: str): # clone a gittea repo using optional security token into dest dirand return a path to the directory + # return dest -def public_notes(src: str): # return a list of notes tagged with public from an obsidian directory - # build vault from source - vault = Vault(src) - if vault: - print ("found vault") - else: - print("could not find vault") - return [] +# def public_notes(src: str): # return a list of notes tagged with public from an obsidian directory +# # build vault from source +# vault = Vault(src) +# if vault: +# print ("found vault") +# else: +# print("could not find vault") +# return [] - # return a list ofnotes - return vault.get_notes_with_tag("public") +# # return a list ofnotes +# return vault.get_notes_with_tag("public") -def buld_public_vault(src: str, dest: str): # build the public vault in dest from an obsidian repo in src - for note in public_notes(src): - print(note.title) - shutil.copy2(f"{note.path}", dest) +# def buld_public_vault(src: str, dest: str): # build the public vault in dest from an obsidian repo in src +# for note in public_notes(src): +# print(note.title) +# shutil.copy2(f"{note.path}", dest) diff --git a/app/requirements.txt b/app/requirements.txt index ad45c3c..6522df1 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,2 +1,5 @@ flask markdown +obsidianmd-parser +GitPython +py-gitea