Markdown (.md) support
This commit is contained in:
15
src/index.rs
15
src/index.rs
@@ -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?);
|
||||
|
||||
|
Reference in New Issue
Block a user