This commit is contained in:
2024-11-08 19:45:52 +03:00
parent aa84cc8793
commit 19988900c6
7 changed files with 129 additions and 7 deletions

View File

@@ -7,7 +7,9 @@ import os
import markdown
import re
sources_dir = "/Users/despiegk1/code/git.ourworld.tf/freeflowuniverse/heroweb/research/dancing_banner/"
sources_dir = os.path.expanduser("~/code/git.ourworld.tf/tfgrid/www_threefold4/poc")
if not os.path.exists(sources_dir):
raise RuntimeError(f"The source directory '{sources_dir}' does not exist.")
static_dir = f"{sources_dir}/static"
content_dir = f"{sources_dir}/content"
@@ -15,20 +17,20 @@ def get_content(name: str) -> str:
"""Get content by name from either HTML or markdown files in content directory"""
# Remove any leading/trailing slashes
name = name.strip('/')
# Check for file with .html extension
html_path = os.path.join(content_dir, f"{name}.html")
if os.path.exists(html_path):
with open(html_path, 'r') as f:
return f.read()
# Check for file with .md extension
md_path = os.path.join(content_dir, f"{name}.md")
if os.path.exists(md_path):
with open(md_path, 'r') as f:
content = f.read()
return markdown.markdown(content)
return f"[[{name} not found]]"
def process_content(content: str) -> str:
@@ -36,7 +38,7 @@ def process_content(content: str) -> str:
def replace_content(match):
name = match.group(1)
return get_content(name)
# Replace all [[name]] patterns
return re.sub(r'\[\[(.*?)\]\]', replace_content, content)
@@ -69,7 +71,7 @@ async def favicon():
raise HTTPException(status_code=404, detail="Favicon not found")
@app.get("/", response_class=HTMLResponse)
async def read_index(request: Request):
async def read_index(request: Request):
template = env.get_template("index.html")
content = template.render(request=request)
return process_content(content)