generated from hjess/PythonTemplateProject
Lets make the frontpage in markdown too
Some checks failed
Build, Push, and Deploy to Nomad / docker-nomad (push) Has been cancelled
Some checks failed
Build, Push, and Deploy to Nomad / docker-nomad (push) Has been cancelled
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import os
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from app.services.markdown_render import render_markdown_with_jinja # Your custom renderer
|
||||
from fastapi import FastAPI
|
||||
from app.services.markdown_render import MarkdownRenderer
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
|
||||
@@ -12,7 +11,7 @@ class MarkdownProcessor:
|
||||
'index.html' per category directory using a custom rendering engine.
|
||||
"""
|
||||
|
||||
def __init__(self, input_dir: str, templates_dir: str):
|
||||
def __init__(self, input_dir: str, templates_dir: str,app:FastAPI=None):
|
||||
"""
|
||||
Initialize the MarkdownProcessor.
|
||||
|
||||
@@ -22,6 +21,8 @@ class MarkdownProcessor:
|
||||
"""
|
||||
self.input_dir = input_dir
|
||||
self.env = Environment(loader=FileSystemLoader(templates_dir))
|
||||
self.app = app
|
||||
|
||||
|
||||
def _process_markdown_files_in_directory(self, directory_path: str) -> list:
|
||||
"""
|
||||
@@ -33,15 +34,21 @@ class MarkdownProcessor:
|
||||
Returns:
|
||||
list: A list of processed sections containing metadata and rendered content.
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
sections = []
|
||||
|
||||
|
||||
|
||||
for file in sorted(os.listdir(directory_path)):
|
||||
if file.endswith(".md"):
|
||||
file_path = os.path.join(directory_path, file)
|
||||
with open(file_path, "r", encoding="utf-8") as md_file:
|
||||
markdown_content = md_file.read()
|
||||
|
||||
markdown_render = MarkdownRenderer(file_path=file_path,app=self.app)
|
||||
# Process Markdown and Jinja2
|
||||
rendered_content, metadata = render_markdown_with_jinja(markdown_content)
|
||||
|
||||
rendered_content, metadata = markdown_render.render_markdown_with_jinja ( markdown_content )
|
||||
|
||||
# Append the section to the list
|
||||
sections.append({
|
||||
|
||||
Reference in New Issue
Block a user