From 1fc46e3c0bd0075f6ca9eeb50eecad10dbf767b8 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Thu, 22 Apr 2021 05:08:11 -0600 Subject: actually render the readme --- src/templates.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/templates.rs (limited to 'src/templates.rs') diff --git a/src/templates.rs b/src/templates.rs new file mode 100644 index 0000000..bb285fa --- /dev/null +++ b/src/templates.rs @@ -0,0 +1,35 @@ +use std::borrow::Cow; + +use askama::Template; + +use crate::state::State; + +#[derive(Template)] +#[template(path = "index.html")] +pub struct Index<'a> { + pub state: &'a State, +} + +#[derive(Template)] +#[template(path = "about.html")] +pub struct About<'a> { + pub path: &'a str, + pub readme: Cow<'a, str>, +} + +mod filters { + pub fn markdown(s: &str) -> ::askama::Result { + use pulldown_cmark::{Parser, Options, html}; + + let mut options = Options::empty(); + options.insert(Options::ENABLE_STRIKETHROUGH); + options.insert(Options::ENABLE_SMART_PUNCTUATION); + let parser = Parser::new_ext(s, options); + + let mut result = String::new(); + html::push_html(&mut result, parser); + + // TODO mark as safe automatically + Ok(result) + } +} -- cgit v1.2.3