Markdown (.md) support

This commit is contained in:
2025-05-04 22:12:49 +02:00
parent 1b27506149
commit deaad74dc8
2 changed files with 52 additions and 1 deletions

View File

@@ -17,6 +17,11 @@ pub static TERA: LazyLock<Tera> = LazyLock::new(|| {
include_str!("../templates/index.html.jinja"),
)
.unwrap();
tera.add_raw_template(
"markdown.html.jinja",
include_str!("../templates/markdown.html.jinja"),
)
.unwrap();
tera.register_filter("iconize", iconize);
tera.register_filter("from_ico", from_ico);
tera.register_filter("size", size);
@@ -63,6 +68,16 @@ pub async fn render_index(path: &PathBuf, time: Instant) -> AResult<String> {
Ok(tera.render("index.html.jinja", &context)?)
}
pub fn render_markdown(filename: &str, content: &str) -> AResult<String> {
let tera = &*TERA;
let mut context = Context::new();
context.insert("filename", &filename);
context.insert("content", &content);
Ok(tera.render("markdown.html.jinja", &context)?)
}
async fn get_directories(path: &PathBuf) -> AResult<Vec<FileInfo>> {
let mut contents = ReadDirStream::new(tokio::fs::read_dir(&path).await?);