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

@@ -7,6 +7,7 @@ ENV FLASK_APP=app
RUN mkdir /app RUN mkdir /app
COPY app/requirements.txt /app COPY app/requirements.txt /app
RUN pip3 install -r /app/requirements.txt RUN pip3 install -r /app/requirements.txt
COPY app /app COPY app /app
ENTRYPOINT ["flask"] ENTRYPOINT ["flask"]

View File

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

View File

@@ -1,26 +1,39 @@
from obsidian_parser import Vault from obsidian_parser import Vault
import shutil 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"<h1>404</h1><p>Could not find {filename}.md in {filePath}</p>", 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 print("build imported")
return dest # 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 # def public_notes(src: str): # return a list of notes tagged with public from an obsidian directory
# build vault from source # # build vault from source
vault = Vault(src) # vault = Vault(src)
if vault: # if vault:
print ("found vault") # print ("found vault")
else: # else:
print("could not find vault") # print("could not find vault")
return [] # return []
# return a list ofnotes # # return a list ofnotes
return vault.get_notes_with_tag("public") # 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 # 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): # for note in public_notes(src):
print(note.title) # print(note.title)
shutil.copy2(f"{note.path}", dest) # shutil.copy2(f"{note.path}", dest)

View File

@@ -1,2 +1,5 @@
flask flask
markdown markdown
obsidianmd-parser
GitPython
py-gitea